lima-vm/lima · error

expected the depth of the converted host working directory (

Error message

expected the depth of the converted host working directory (%#q) to be at least %d, only got %d

What it means

Besides the native host path, Lima measures the converted `hostCurrentDir` — the POSIX-form path actually handed to rsync (on Windows produced via cygpath/mount mapping). If an fstab mapping or a cygpath quirk maps a deep native directory onto a shallow POSIX path, the converted path fails the same minimum-depth check and the command aborts.

Source

Thrown at cmd/limactl/shell.go:266

		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
		// onto a shallow one. It is always POSIX form, even on Windows.
		if dstWdDepth := pathDepth(hostCurrentDir, false); dstWdDepth < rsyncMinimumSrcDirDepth {
			return fmt.Errorf("expected the depth of the converted host working directory (%#q) to be at least %d, only got %d",
				hostCurrentDir, rsyncMinimumSrcDirDepth, dstWdDepth)
		}
	}

	var destRsyncDir string
	workDir, err := cmd.Flags().GetString("workdir")
	if err != nil {
		return err
	}
	if workDir != "" && syncHostWorkdir {
		return errors.New("cannot use `--workdir` and `--sync` at the same time")
	}
	if syncHostWorkdir {
		destRsyncDir = *inst.Config.User.Home + hostCurrentDir
	}
	hostHomeDir, err := os.UserHomeDir()
	if err == nil && runtime.GOOS == "windows" {
		hostHomeDir, err = mountDirFromWindowsDir(ctx, inst, hostHomeDir)

View on GitHub (pinned to dd909d0973)

Solutions

  1. Inspect the converted path (enable `--debug` to log hostCurrentDir) and fix the fstab/cygpath mapping so depth is preserved.
  2. Sync a directory whose POSIX-converted form is deep enough; avoid mappings that collapse path components.
  3. Verify with `cygpath -u <native dir>` that the converted path has the expected number of components.

Example fix

# /etc/fstab mapping that collapses depth
# before
C:\work /work ntfs binary 0 0
# after — map the drive root instead, preserving depth
C:/ /cygdrive/c ntfs binary,posix=0 0 0
Defensive patterns

Strategy: validation

Validate before calling

posix=$(cygpath -u "$(pwd)"); n=$(echo "$posix" | awk -F/ '{print NF-1}'); [ "$n" -ge 3 ] || { echo 'converted path too shallow: check /etc/fstab mapping'; exit 1; }

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: On Windows (or any host with path conversion), running `limactl shell <instance> --sync <dir>` where the native path is deep enough but `mountDirFromWindowsDir` yields a POSIX path shallower than `rsyncMinimumSrcDirDepth`.

Common situations: Windows hosts with a custom `/etc/fstab` in the MSYS2/Cygwin environment mapping a deep directory onto a short mount point; cygpath reporting success with an unexpected short path; drive-subst or junction setups that collapse path depth.

Related errors


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