{"record":{"id":"c8518aa3702cf95a","repo":"siyuan-note/siyuan","slug":"move-s-to-s-failed-w","errorCode":null,"errorMessage":"move [%s] to [%s] failed: %w","messagePattern":"move \\[(.+?)\\] to \\[(.+?)\\] failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/working_mobile.go","lineNumber":204,"sourceCode":"\t\t\treturn false, fmt.Errorf(\"destination [%s] already exists\", to)\n\t\t} else if !errors.Is(statErr, fs.ErrNotExist) {\n\t\t\treturn false, fmt.Errorf(\"stat destination [%s] failed: %w\", to, statErr)\n\t\t}\n\t\tmoves = append(moves, workspaceDirMove{from: from, to: to})\n\t}\n\n\tvar completed []workspaceDirMove\n\tfor _, move := range moves {\n\t\tif renameErr := os.Rename(move.from, move.to); renameErr != nil {\n\t\t\tvar rollbackErrors []error\n\t\t\tfor i := len(completed) - 1; 0 <= i; i-- {\n\t\t\t\tcompletedMove := completed[i]\n\t\t\t\tif rollbackErr := os.Rename(completedMove.to, completedMove.from); rollbackErr != nil {\n\t\t\t\t\trollbackErrors = append(rollbackErrors, fmt.Errorf(\"rollback [%s] to [%s] failed: %w\",\n\t\t\t\t\t\tcompletedMove.to, completedMove.from, rollbackErr))\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false, errors.Join(append([]error{fmt.Errorf(\"move [%s] to [%s] failed: %w\", move.from, move.to, renameErr)}, rollbackErrors...)...)\n\t\t}\n\t\tcompleted = append(completed, move)\n\t}\n\n\tfor _, move := range completed {\n\t\tlogging.LogInfof(\"moved legacy iOS workspace dir [from=%s, to=%s]\", move.from, move.to)\n\t}\n\treturn true, nil\n}\n\nfunc replaceLegacyIOSWorkspacePath(workspacePaths []string, workspaceBaseDir, defaultWorkspaceDir string) []string {\n\tfor i, workspacePath := range workspacePaths {\n\t\tif filepath.Clean(workspacePath) == filepath.Clean(workspaceBaseDir) {\n\t\t\tworkspacePaths[i] = defaultWorkspaceDir\n\t\t}\n\t}\n\treturn DeduplicateWorkspacePaths(workspacePaths)\n}","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/working_mobile.go#L186-L222","documentation":"This is the primary failure of the legacy iOS workspace migration: moving one known legacy directory (e.g. 'data', 'conf', 'temp') into the new default workspace with os.Rename failed. All completed moves are rolled back and the whole operation reports false, with this error as the head of the joined error chain. It means the workspace layout was left (or restored to) its legacy state.","triggerScenarios":"initWorkspaceDirMobile detects a legacy iOS workspace layout and migrateLegacyIOSWorkspace's os.Rename(from, to) returns an error — source missing, destination created between the Lstat check and the rename, cross-device rename not possible, or permission/EBUSY on either path.","commonSituations":"Upgrade across SiYuan versions that changed the workspace layout; a TOCTOU race where the new workspace directory got populated by another process between existence check and rename; source directory deleted or locked by cloud sync restoring files; volume or app-container permission issues on iOS.","solutions":["Inspect the wrapped renameErr (%w): ENOENT means the source vanished (let sync settle and restart), EEXIST/ENOTEMPTY means the destination appeared (remove or merge it), EACCES/EPERM means fix permissions","Ensure no other SiYuan instance or sync client is writing to the workspace, then restart the app so migration re-runs atomically","Free disk space and verify the source and destination are on the same volume if EXDEV/ENOSPC is reported","As a last resort, manually move the listed directory from the legacy location into the default workspace and restart"],"exampleFix":"// before: destination check and rename are not atomic, so a racing creator causes failure\nif _, statErr := os.Lstat(to); statErr == nil {\n    return false, fmt.Errorf(\"destination [%s] already exists\", to)\n}\n...\nif renameErr := os.Rename(move.from, move.to); renameErr != nil {\n// after: tolerate the destination already being moved (rename over empty dir succeeds) and re-check error kind\nif renameErr := os.Rename(move.from, move.to); renameErr != nil {\n    if errors.Is(renameErr, os.ErrNotExist) {\n        logging.LogWarnf(\"legacy dir [%s] already gone, skipping\", move.from)\n        continue\n    }\n    return false, fmt.Errorf(\"move [%s] to [%s] failed: %w\", move.from, move.to, renameErr)\n}","handlingStrategy":"retry","validationCode":"for _, name := range knownEntries {\n    from := filepath.Join(legacyWorkspaceDir, name)\n    to := filepath.Join(defaultWorkspaceDir, name)\n    if _, err := os.Lstat(to); err == nil {\n        return fmt.Errorf(\"destination [%s] already exists; resolve before migration\", to)\n    }\n    if _, err := os.Lstat(from); errors.Is(err, fs.ErrNotExist) {\n        return fmt.Errorf(\"source [%s] missing; let sync settle before migration\", from)\n    }\n}","typeGuard":"func isRenameFailure(err error) (src, dst string, ok bool) {\n    msg := err.Error()\n    if strings.HasPrefix(msg, \"move [\") {\n        parts := strings.Split(msg, \"[\")\n        if len(parts) >= 3 {\n            return strings.TrimSuffix(parts[1], \"]\"), strings.TrimSuffix(strings.SplitN(parts[2], \"]\", 2)[0], \"\"), true\n        }\n    }\n    return \"\", \"\", false\n}","tryCatchPattern":"if moved, err := migrateLegacyIOSWorkspace(...); err != nil {\n    if errors.Is(err, os.ErrPermission) || errors.Is(err, syscall.EBUSY) {\n        time.Sleep(retryDelay)\n        moved, err = migrateLegacyIOSWorkspace(...)\n    }\n    if err != nil {\n        logging.LogErrorf(\"workspace migration failed, legacy layout preserved: %v\", err)\n        return err\n    }\n}","preventionTips":["Quit all SiYuan instances and sync clients before upgrading across versions that change workspace layout","Do not create files at the new workspace's expected entry names (data, conf, temp) before first launch","Retry startup after transient failures — the rollback keeps the legacy layout intact for a clean retry","Verify same-volume locations and sufficient free space for both source and destination directories"],"tags":["filesystem","migration","rename","ios","workspace"],"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"}