{"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":1023,"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":1005,"sourceCodeEnd":1041,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/import.go#L1005-L1041","documentation":"This is a legacy 'rename doc' path in import.go that moves previously exported/imported paths within a notebook (oldPaths -> renamePaths mapping, sorted shallowest-first). If filelock.Rename fails for any pair, the function logs the underlying OS error and replaces it with the generic message 'rename path failed'. The real cause (locked file, missing source, cross-device link) is only visible in the kernel log.","triggerScenarios":"ImportSY processing a package whose payload includes path-rename operations, when filelock.Rename(oldPath, newPath) fails — e.g. the source .sy file is missing, the target path already exists, file locks/permissions block the move on Windows, or the data dir is on a different filesystem.","commonSituations":"1) Antivirus/indexer (or another SiYuan instance) holds the file open on Windows, breaking rename. 2) Stale renamePaths referencing documents deleted between export and import. 3) Workspace on a network mount where rename semantics differ. 4) Permission mismatch after copying a workspace with different ownership.","solutions":["Check the kernel log for the 'rename path from [...] to [...] failed' line to find the real OS error and the specific paths involved.","Ensure no other SiYuan instance / antivirus locks files in the workspace's data directory, then retry the import.","Verify the source .sy files referenced by oldPaths exist; restore them or re-export the package.","Run the kernel with sufficient permissions over the workspace, and keep data on a local filesystem rather than a network share."],"exampleFix":"// before\nif err = filelock.Rename(oldPath, newPath); err != nil {\n    err = errors.New(\"rename path failed\")\n}\n// after\nif err = filelock.Rename(oldPath, newPath); err != nil {\n    err = fmt.Errorf(\"rename path from [%s] to [%s] failed: %w\", oldPath, newPath, err)\n}","handlingStrategy":"try-catch","validationCode":"for (const p of [oldPath, newPath]) {\n  if (!fs.existsSync(p) && fs.existsSync(oldPath)) { throw new Error(`missing rename source ${oldPath}`); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await importSY(boxID, src);\n} catch (e) {\n  if (e.msg === 'rename path failed') {\n    console.error('Check kernel log for \"rename path from ... failed\"; close other SiYuan instances and retry');\n  }\n  throw e;\n}","preventionTips":["Keep only one kernel instance per workspace","Exclude the workspace data dir from antivirus real-time locking (especially on Windows)","Keep the workspace on a local filesystem, not network shares","Do not manually delete .sy files referenced by import packages"],"tags":["filesystem","rename","filelock","siyuan"],"backgroundTag":"file-write-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}