lima-vm/lima · error

failed to determine the host directory to sync: %w

Error message

failed to determine the host directory to sync: %w

What it means

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.

Source

Thrown at cmd/limactl/shell.go:245

	// hostCurrentDirNative is the path as the host sees it. hostCurrentDir is the
	// form the guest and the copy tool receive, which on Windows differs.
	var hostCurrentDir, hostCurrentDirNative string
	if syncDirVal != "" {
		hostCurrentDirNative, err = filepath.Abs(syncDirVal)
	} else {
		hostCurrentDirNative, err = os.Getwd()
	}
	if err == nil {
		hostCurrentDir = hostCurrentDirNative
		if runtime.GOOS == "windows" {
			hostCurrentDir, err = mountDirFromWindowsDir(ctx, inst, hostCurrentDirNative)
		}
	}

	if err != nil {
		// An empty hostCurrentDir would reach rsync as the toolchain root.
		if syncHostWorkdir {
			return fmt.Errorf("failed to determine the host directory to sync: %w", err)
		}
		changeDirCmd = "false"
		logrus.WithError(err).Warn("failed to get the current directory")
	}
	if syncHostWorkdir {
		if _, err := exec.LookPath(string(copytool.BackendRsync)); err != nil {
			return fmt.Errorf("rsync is required for `--sync` but not found: %w", err)
		}

		// Measure the host's own path. The form hostCurrentDir carries on Windows
		// adds one component (/c/...) or two (/cygdrive/c/...).
		srcWdDepth := pathDepth(hostCurrentDirNative, runtime.GOOS == "windows")
		if srcWdDepth < rsyncMinimumSrcDirDepth {
			return fmt.Errorf("expected the depth of the host working directory (%#q) to be at least %d, only got %d (Hint: %s)",
				hostCurrentDirNative, rsyncMinimumSrcDirDepth, srcWdDepth, "cd to a deeper directory")
		}
		// rsync acts on hostCurrentDir, so measure that too: cygpath can report
		// success without writing a path, and an fstab can map a deep directory

View on GitHub (pinned to dd909d0973)

Solutions

  1. `cd` to a valid, existing directory before running `limactl shell --sync`.
  2. If passing `--sync <dir>`, confirm the path exists and is absolute-able (run `ls <dir>` first).
  3. On Windows, verify the drive mapping works (`cygpath -u C:\some\dir` returns a POSIX path).

Example fix

# before (from a deleted directory)
limactl shell default --sync
# after
cd ~/project && limactl shell default --sync
Defensive patterns

Strategy: validation

Validate before calling

dir="${1:-$PWD}"; [ -d "$dir" ] || { echo "directory does not exist: $dir"; exit 1; }

Type guard

null

Try / catch

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

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/5c225808fbbbd41c. Report an issue: GitHub.