{"record":{"id":"5c225808fbbbd41c","repo":"lima-vm/lima","slug":"failed-to-determine-the-host-directory-to-sync-w","errorCode":null,"errorMessage":"failed to determine the host directory to sync: %w","messagePattern":"failed to determine the host directory to sync: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/shell.go","lineNumber":245,"sourceCode":"\t// hostCurrentDirNative is the path as the host sees it. hostCurrentDir is the\n\t// form the guest and the copy tool receive, which on Windows differs.\n\tvar hostCurrentDir, hostCurrentDirNative string\n\tif syncDirVal != \"\" {\n\t\thostCurrentDirNative, err = filepath.Abs(syncDirVal)\n\t} else {\n\t\thostCurrentDirNative, err = os.Getwd()\n\t}\n\tif err == nil {\n\t\thostCurrentDir = hostCurrentDirNative\n\t\tif runtime.GOOS == \"windows\" {\n\t\t\thostCurrentDir, err = mountDirFromWindowsDir(ctx, inst, hostCurrentDirNative)\n\t\t}\n\t}\n\n\tif err != nil {\n\t\t// An empty hostCurrentDir would reach rsync as the toolchain root.\n\t\tif syncHostWorkdir {\n\t\t\treturn fmt.Errorf(\"failed to determine the host directory to sync: %w\", err)\n\t\t}\n\t\tchangeDirCmd = \"false\"\n\t\tlogrus.WithError(err).Warn(\"failed to get the current directory\")\n\t}\n\tif syncHostWorkdir {\n\t\tif _, err := exec.LookPath(string(copytool.BackendRsync)); err != nil {\n\t\t\treturn fmt.Errorf(\"rsync is required for `--sync` but not found: %w\", err)\n\t\t}\n\n\t\t// Measure the host's own path. The form hostCurrentDir carries on Windows\n\t\t// adds one component (/c/...) or two (/cygdrive/c/...).\n\t\tsrcWdDepth := pathDepth(hostCurrentDirNative, runtime.GOOS == \"windows\")\n\t\tif srcWdDepth < rsyncMinimumSrcDirDepth {\n\t\t\treturn fmt.Errorf(\"expected the depth of the host working directory (%#q) to be at least %d, only got %d (Hint: %s)\",\n\t\t\t\thostCurrentDirNative, rsyncMinimumSrcDirDepth, srcWdDepth, \"cd to a deeper directory\")\n\t\t}\n\t\t// rsync acts on hostCurrentDir, so measure that too: cygpath can report\n\t\t// success without writing a path, and an fstab can map a deep directory","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/shell.go#L227-L263","documentation":"Before syncing, Lima must resolve the host directory to copy: either the value passed to `--sync` converted to an absolute path, or `os.Getwd()` when `--sync` was given no explicit directory (on Windows it additionally converts the path via cygpath/mount lookup). If any of those calls fail while `--sync` is in use, shellAction aborts because an empty directory would be handed to rsync as the toolchain root and sync the wrong thing.","triggerScenarios":"`filepath.Abs(syncDirVal)` fails (e.g. malformed path), `os.Getwd()` fails because the current working directory was deleted or lacks permissions, or on Windows `mountDirFromWindowsDir` fails to translate the path.","commonSituations":"Running `limactl shell --sync` from a directory that was removed while the shell sat in it; a deleted/renamed parent; a broken Windows drive mapping so cygpath translation fails.","solutions":["`cd` to a valid, existing directory before running `limactl shell --sync`.","If passing `--sync <dir>`, confirm the path exists and is absolute-able (run `ls <dir>` first).","On Windows, verify the drive mapping works (`cygpath -u C:\\some\\dir` returns a POSIX path)."],"exampleFix":"# before (from a deleted directory)\nlimactl shell default --sync\n# after\ncd ~/project && limactl shell default --sync","handlingStrategy":"validation","validationCode":"dir=\"${1:-$PWD}\"; [ -d \"$dir\" ] || { echo \"directory does not exist: $dir\"; exit 1; }","typeGuard":"null","tryCatchPattern":"if ! out=$(limactl shell \"$inst\" --sync . 2>&1); then echo \"$out\" | grep 'host directory to sync' && cd \"$VALID_DIR\" && exec limactl shell \"$inst\" --sync .; fi","preventionTips":["Always cd to a verified directory before `--sync` without an explicit path.","Pass an explicit existing directory to `--sync <dir>` in scripts instead of relying on cwd.","On Windows, sanity-check `cygpath -u <dir>` output before syncing.","Avoid running from directories that may be deleted/recreated by builds."],"tags":["cli","limactl","filesystem","sync","path-resolution"],"backgroundTag":"cwd-unavailable","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}