MCPcopy Index your code
hub / github.com/dagger/dagger / loadWorkspaceFromDeclaredRef

Method loadWorkspaceFromDeclaredRef

engine/server/session_workspaces.go:188–211  ·  view source on GitHub ↗
(ctx context.Context, client *daggerClient, workspaceRef string)

Source from the content-addressed store, hash-verified

186}
187
188func (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
213func isWorkspaceNotFound(err error) bool {
214 return errors.Is(err, os.ErrNotExist) || status.Code(err) == codes.NotFound

Callers 1

ensureWorkspaceLoadedMethod · 0.95

Calls 6

isWorkspaceNotFoundFunction · 0.85
AbsPathMethod · 0.80
StatCallerHostPathMethod · 0.80
IsDirMethod · 0.45

Tested by

no test coverage detected