MCPcopy Create free account
hub / github.com/Facets-cloud/flow / resolveWorkDir

Function resolveWorkDir

internal/app/add.go:302–327  ·  view source on GitHub ↗

resolveWorkDir canonicalizes path to an absolute path, verifies it exists (or mkdirs it if create=true). Returns the abs path.

(path string, create bool)

Source from the content-addressed store, hash-verified

300// resolveWorkDir canonicalizes path to an absolute path, verifies it
301// exists (or mkdirs it if create=true). Returns the abs path.
302func resolveWorkDir(path string, create bool) (string, error) {
303 if path == "" {
304 return "", fmt.Errorf("work-dir is empty")
305 }
306 abs, err := filepath.Abs(path)
307 if err != nil {
308 return "", fmt.Errorf("resolve %s: %w", path, err)
309 }
310 info, err := os.Stat(abs)
311 if err == nil {
312 if !info.IsDir() {
313 return "", fmt.Errorf("work-dir %s is not a directory", abs)
314 }
315 return abs, nil
316 }
317 if !os.IsNotExist(err) {
318 return "", fmt.Errorf("stat %s: %w", abs, err)
319 }
320 if !create {
321 return "", fmt.Errorf("work-dir %s does not exist (pass --mkdir to create)", abs)
322 }
323 if err := os.MkdirAll(abs, 0o755); err != nil {
324 return "", fmt.Errorf("mkdir %s: %w", abs, err)
325 }
326 return abs, nil
327}
328
329// uniqueSlug returns base if no row with that slug exists in table;
330// otherwise appends -2, -3, ... until it finds an unused one.

Callers 5

addOwnerFunction · 0.85
addPlaybookFunction · 0.85
cmdUpdateTaskFunction · 0.85
addProjectFunction · 0.85
addTaskFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected