{"record":{"id":"553e46767a5b5129","repo":"siyuan-note/siyuan","slug":"rename-path-failed","errorCode":null,"errorMessage":"rename path failed","messagePattern":"rename path failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/import.go","lineNumber":749,"sourceCode":"\t\t\t\tbuf.WriteString(\"/\")\n\t\t\t}\n\t\t}\n\t\tnewPath := buf.String()\n\t\trenamePaths[originalPath] = filepath.Join(unzipRootPath, newPath)\n\t}\n\n\tvar oldPaths []string\n\tfor oldPath := range renamePaths {\n\t\toldPaths = append(oldPaths, oldPath)\n\t}\n\tsort.Slice(oldPaths, func(i, j int) bool {\n\t\treturn strings.Count(oldPaths[i], string(os.PathSeparator)) < strings.Count(oldPaths[j], string(os.PathSeparator))\n\t})\n\tfor i, oldPath := range oldPaths {\n\t\tnewPath := renamePaths[oldPath]\n\t\tif err = filelock.Rename(oldPath, newPath); err != nil {\n\t\t\tlogging.LogErrorf(\"rename path from [%s] to [%s] failed: %s\", oldPath, renamePaths[oldPath], err)\n\t\t\terr = errors.New(\"rename path failed\")\n\t\t\treturn\n\t\t}\n\n\t\tdelete(renamePaths, oldPath)\n\t\tvar toRemoves []string\n\t\tnewRenamedPaths := map[string]string{}\n\t\tfor oldP, newP := range renamePaths {\n\t\t\tif strings.HasPrefix(oldP, oldPath) {\n\t\t\t\trenamedOldP := strings.Replace(oldP, oldPath, newPath, 1)\n\t\t\t\tnewRenamedPaths[renamedOldP] = newP\n\t\t\t\ttoRemoves = append(toRemoves, oldPath)\n\t\t\t}\n\t\t}\n\t\tfor _, toRemove := range toRemoves {\n\t\t\tdelete(renamePaths, toRemove)\n\t\t}\n\t\tmaps.Copy(renamePaths, newRenamedPaths)\n\t\tfor j := i + 1; j < len(oldPaths); j++ {","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/import.go#L731-L767","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check disk space on the volume containing util.DataDir and ensure it has room for the rename operations.","Verify write permissions on the notebook directory and the unzip temp directory.","Disable or whitelist the SiYuan data directory in antivirus / file-indexing software (especially on Windows).","Ensure the temp extraction directory and the data directory are on the same filesystem mount to avoid cross-device rename failures.","Check the kernel log for the specific underlying error logged at import.go:748 (logging.LogErrorf with old/new paths)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before ImportSYZip, verify the temp and target directories are writable\nfunc checkRenameFeasibility(targetDir string) error {\n    testFile := filepath.Join(targetDir, \".siyuan-rename-test\")\n    if err := os.WriteFile(testFile, []byte(\"test\"), 0644); err != nil {\n        return fmt.Errorf(\"target dir not writable: %w\", err)\n    }\n    renamedFile := testFile + \"-renamed\"\n    if err := os.Rename(testFile, renamedFile); err != nil {\n        os.Remove(testFile)\n        return fmt.Errorf(\"rename not supported on target dir: %w\", err)\n    }\n    os.Remove(renamedFile)\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Wrap ImportSYZip and check for rename failure\ncreatedBoxID, err := model.ImportSYZip(boxID, localPath, toPath)\nif err != nil && strings.Contains(err.Error(), \"rename path failed\") {\n    logging.LogErrorf(\"import failed during file rename — check disk space, permissions, and file locks\")\n    // Optionally retry once after a short delay, or surface to user\n}","preventionTips":["Ensure the data directory and temp directory are on the same filesystem mount to avoid cross-device rename failures.","Free sufficient disk space before importing large archives.","Close antivirus and file-indexing software that may lock files during rename on Windows.","Verify write permissions on the target notebook directory before starting import."],"tags":["import","filesystem","sy-zip","rename","io"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}