siyuan-note/siyuan · error

rename path failed

Error message

rename path failed

What it means

Thrown by ImportSYZip when filelock.Rename fails while renaming .sy files on disk to match regenerated block IDs. After the kernel assigns new block IDs to every node in the imported trees, the physical .sy file paths must be updated to reflect the new root IDs. The rename loop processes paths shallowest-first to handle parent-child path dependencies, and any single rename failure aborts the entire import.

Source

Thrown at kernel/model/import.go:749

				buf.WriteString("/")
			}
		}
		newPath := buf.String()
		renamePaths[originalPath] = filepath.Join(unzipRootPath, newPath)
	}

	var oldPaths []string
	for oldPath := range renamePaths {
		oldPaths = append(oldPaths, oldPath)
	}
	sort.Slice(oldPaths, func(i, j int) bool {
		return strings.Count(oldPaths[i], string(os.PathSeparator)) < strings.Count(oldPaths[j], string(os.PathSeparator))
	})
	for i, oldPath := range oldPaths {
		newPath := renamePaths[oldPath]
		if err = filelock.Rename(oldPath, newPath); err != nil {
			logging.LogErrorf("rename path from [%s] to [%s] failed: %s", oldPath, renamePaths[oldPath], err)
			err = errors.New("rename path failed")
			return
		}

		delete(renamePaths, oldPath)
		var toRemoves []string
		newRenamedPaths := map[string]string{}
		for oldP, newP := range renamePaths {
			if strings.HasPrefix(oldP, oldPath) {
				renamedOldP := strings.Replace(oldP, oldPath, newPath, 1)
				newRenamedPaths[renamedOldP] = newP
				toRemoves = append(toRemoves, oldPath)
			}
		}
		for _, toRemove := range toRemoves {
			delete(renamePaths, toRemove)
		}
		maps.Copy(renamePaths, newRenamedPaths)
		for j := i + 1; j < len(oldPaths); j++ {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Check disk space on the volume containing util.DataDir and ensure it has room for the rename operations.
  2. Verify write permissions on the notebook directory and the unzip temp directory.
  3. Disable or whitelist the SiYuan data directory in antivirus / file-indexing software (especially on Windows).
  4. Ensure the temp extraction directory and the data directory are on the same filesystem mount to avoid cross-device rename failures.
  5. Check the kernel log for the specific underlying error logged at import.go:748 (logging.LogErrorf with old/new paths).
Defensive patterns

Strategy: try-catch

Validate before calling

// Before ImportSYZip, verify the temp and target directories are writable
func checkRenameFeasibility(targetDir string) error {
    testFile := filepath.Join(targetDir, ".siyuan-rename-test")
    if err := os.WriteFile(testFile, []byte("test"), 0644); err != nil {
        return fmt.Errorf("target dir not writable: %w", err)
    }
    renamedFile := testFile + "-renamed"
    if err := os.Rename(testFile, renamedFile); err != nil {
        os.Remove(testFile)
        return fmt.Errorf("rename not supported on target dir: %w", err)
    }
    os.Remove(renamedFile)
    return nil
}

Try / catch

// Wrap ImportSYZip and check for rename failure
createdBoxID, err := model.ImportSYZip(boxID, localPath, toPath)
if err != nil && strings.Contains(err.Error(), "rename path failed") {
    logging.LogErrorf("import failed during file rename — check disk space, permissions, and file locks")
    // Optionally retry once after a short delay, or surface to user
}

Prevention

When it happens

Trigger: Calling ImportSYZip where filelock.Rename(oldPath, newPath) returns an error for any entry in renamePaths. This occurs after block-ID regeneration at import.go:745-751 when the loop iterates sorted oldPaths and renames each file from its original path to the new ID-based path.

Common situations: Insufficient disk space during rename on the same volume. Permission denied on the source or target directory. Path length exceeding OS limits on Windows. Antivirus or file-indexing software locking files on Windows. Cross-device rename attempt when temp extraction and data directory are on different mounts.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/553e46767a5b5129. Report an issue: GitHub.