{"record":{"id":"0323889eaed6d277","repo":"siyuan-note/siyuan","slug":"install-marketplace-package-failed-w-rollback-f","errorCode":null,"errorMessage":"install marketplace package failed: %w; rollback failed: %s","messagePattern":"install marketplace package failed: %w; rollback failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"kernel/bazaar/install.go","lineNumber":236,"sourceCode":"\t\treturn statErr\n\t}\n\tif targetExists && !update && containsFile {\n\t\treturn errors.New(\"marketplace package install path already exists\")\n\t}\n\tif update && !targetExists {\n\t\treturn os.ErrNotExist\n\t}\n\n\tif targetExists {\n\t\tif err = os.Rename(installPath, backupPath); err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\tif err = os.Rename(stagingPath, installPath); err != nil {\n\t\tif targetExists {\n\t\t\tif rollbackErr := os.Rename(backupPath, installPath); rollbackErr != nil {\n\t\t\t\tpreserveOperationPath = true\n\t\t\t\treturn fmt.Errorf(\"install marketplace package failed: %w; rollback failed: %s\", err, rollbackErr)\n\t\t\t}\n\t\t}\n\t\treturn\n\t}\n\tif targetExists {\n\t\tif removeErr := os.RemoveAll(operationPath); removeErr != nil {\n\t\t\tlogging.LogWarnf(\"remove package backup [%s] failed: %s\", backupPath, removeErr)\n\t\t}\n\t}\n\treturn\n}\n\n// InstallLocalPackage 从已解压并验证的目录安装本地集市包。\nfunc InstallLocalPackage(sourcePath, installPath, pkgType, packageName string, update bool) (err error) {\n\tvar fallbackInstallTime time.Time\n\tif info, statErr := os.Stat(installPath); statErr == nil {\n\t\tfallbackInstallTime = info.ModTime()\n\t}","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/bazaar/install.go#L218-L254","documentation":"replacePackageDirectory swaps the staged directory into installPath with os.Rename. If that rename fails after an old target was moved to a backup, it attempts to roll back by restoring the backup; when the rollback ALSO fails, it reports both the original install failure and the rollback failure, and preserves the operation directory for manual recovery.","triggerScenarios":"The rename or restore fails due to filesystem-level problems: target directory locked by another process, cross-device rename, permission issues, or the backup path no longer renameable.","commonSituations":"Antivirus/indexer (or another SiYuan instance) holding handles inside the package directory on Windows; installPath on a different mount than the staging dir (os.Rename across devices fails); disk full or permission loss mid-update leaving the package dir in a half-replaced state.","solutions":["Inspect the preserved operation path mentioned by the kernel logs and manually restore/repair the package directory","Close processes holding handles in the package dir (AV scanners, editors, sync clients) and retry the install/update","Ensure staging dir (util.TempDir) and the data/packages dir are on the same filesystem/volume","Check disk space and write permissions on the packages directory"],"exampleFix":"// before: temp on /tmp (tmpfs), packages on /home -> os.Rename EXDEV\n// after: set the workspace temp directory on the same volume as data/, then retry the update","handlingStrategy":"try-catch","validationCode":"if st, err := os.Stat(installPath); err == nil {\n    if ok, _ := hasOpenHandles(installPath); ok { return fmt.Errorf(\"package dir busy; close apps using it\") }\n}\n// ensure staging and target share a device\nif !sameDevice(util.TempDir, filepath.Dir(installPath)) { return errors.New(\"staging volume differs from install volume\") }","typeGuard":null,"tryCatchPattern":"if err := installPackage(...); err != nil && strings.Contains(err.Error(), \"rollback failed\") {\n    // state on disk may be inconsistent: locate the preserved operation path,\n    // manually restore backup or remove staging, then retry with a clean dir\n}","preventionTips":["Keep util.TempDir and data/ on the same filesystem so rename is atomic","Exclude the workspace from antivirus/sync tools that lock directories mid-rename","Ensure free disk space and writable permissions before updates","After a failed update, verify package dir integrity before launching plugins"],"tags":["filesystem","bazaar","rollback","rename"],"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"}