juicedata/juicefs · error

failed to get absolute path of %s: %s

Error message

failed to get absolute path of %s: %s

What it means

After the source backup file is stat'ed, `open` calls filepath.Abs(src) to compute its absolute path, which is used to build the file:// object storage for reading the backup. filepath.Abs only fails when the current working directory cannot be determined (e.g. the cwd was deleted), so this error is rare and environmental, not caused by the path string itself.

Source

Thrown at cmd/load.go:129

	if key != "" {
		privKey, err := object.ParsePrivateKeyFromPem([]byte(loadEncrypt(key)), []byte(os.Getenv("JFS_RSA_PASSPHRASE")))
		if err != nil {
			if errors.Is(err, object.ErrKeyNeedPasswd) {
				return nil, fmt.Errorf("%w: please set the 'JFS_RSA_PASSPHRASE' environment variable", err)
			}
			return nil, fmt.Errorf("parse private key: %s", err)
		}
		encryptor, err := object.NewDataEncryptor(object.NewKeyEncryptor(privKey), algo)
		if err != nil {
			return nil, err
		}
		if _, err := os.Stat(src); err != nil {
			return nil, fmt.Errorf("failed to stat %s: %s", src, err)
		}
		var srcAbsPath string
		srcAbsPath, err = filepath.Abs(src)
		if err != nil {
			return nil, fmt.Errorf("failed to get absolute path of %s: %s", src, err)
		}
		fileBlob, err := object.CreateStorage("file", strings.TrimSuffix(src, filepath.Base(srcAbsPath)), "", "", "")
		if err != nil {
			return nil, err
		}
		blob := object.NewEncrypted(fileBlob, encryptor)
		fp, ioErr = blob.Get(context.Background(), filepath.Base(srcAbsPath), 0, -1)
	} else {
		fp, ioErr = os.Open(src)
	}
	if ioErr != nil {
		return nil, ioErr
	}
	if strings.HasSuffix(src, ".gz") {
		var err error
		r, err = gzip.NewReader(fp)
		if err != nil {
			return nil, err

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. cd to an existing directory (e.g. `cd /`) and re-run the command
  2. Restart the shell or container so it gets a valid working directory
  3. Always invoke juicefs with an absolute backup path from a stable directory

Example fix

// before
cd /tmp/workdir && rm -rf /tmp/workdir && juicefs load meta.sqlite3 backup.json
// after
cd / && juicefs load meta.sqlite3 /tmp/backup.json
Defensive patterns

Strategy: validation

Validate before calling

if wd, err := os.Getwd(); err != nil {
    return fmt.Errorf("working directory invalid: %v", err)
}

Try / catch

out, err := exec.Command("juicefs", "load", ...).CombinedOutput()
if err != nil && strings.Contains(string(out), "absolute path") {
    log.Fatalf("re-run from a valid cwd: %v", err)
}

Prevention

When it happens

Trigger: Calling `juicefs load`/`convert` from a shell whose current working directory has been removed (e.g. the directory was deleted or the container workdir was unmounted) so os.Getwd() inside filepath.Abs fails.

Common situations: Long-running shells where tmp/workspace directories were cleaned; Kubernetes/Docker exec sessions whose workdir vanished; scripts that `rm -rf` their own directory before running load.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/ccd139120b529a1c. Report an issue: GitHub.