(ctx context.Context, client *daggerClient, workspaceRef string)
| 186 | } |
| 187 | |
| 188 | func (srv *Server) loadWorkspaceFromDeclaredRef(ctx context.Context, client *daggerClient, workspaceRef string) error { |
| 189 | // Resolve as local path first (relative to the connecting client's cwd). |
| 190 | // If not found, fall back to parsing as a git workspace ref. |
| 191 | localPath, err := client.engineUtilClient.AbsPath(ctx, workspaceRef) |
| 192 | if err == nil { |
| 193 | localStat, statErr := client.engineUtilClient.StatCallerHostPath(ctx, localPath, true) |
| 194 | switch { |
| 195 | case statErr == nil: |
| 196 | if !localStat.IsDir() { |
| 197 | return fmt.Errorf("workspace %q: local path is not a directory", workspaceRef) |
| 198 | } |
| 199 | return srv.loadWorkspaceFromHostPath(ctx, client, localPath) |
| 200 | case !isWorkspaceNotFound(statErr): |
| 201 | return fmt.Errorf("workspace %q: checking local path: %w", workspaceRef, statErr) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | if remoteErr := srv.loadWorkspaceFromRemote(ctx, client, workspaceRef); remoteErr == nil { |
| 206 | return nil |
| 207 | } else if err == nil { |
| 208 | return fmt.Errorf("workspace %q did not resolve as local path or git ref: %w", workspaceRef, remoteErr) |
| 209 | } |
| 210 | return fmt.Errorf("workspace %q: resolving local path: %w", workspaceRef, err) |
| 211 | } |
| 212 | |
| 213 | func isWorkspaceNotFound(err error) bool { |
| 214 | return errors.Is(err, os.ErrNotExist) || status.Code(err) == codes.NotFound |
no test coverage detected