{"record":{"id":"23f4b3f2c78234c0","repo":"siyuan-note/siyuan","slug":"stat-destination-s-failed-w","errorCode":null,"errorMessage":"stat destination [%s] failed: %w","messagePattern":"stat destination \\[(.+?)\\] failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/working_mobile.go","lineNumber":188,"sourceCode":"\tif 0 < len(destinationEntries) {\n\t\treturn false, fmt.Errorf(\"destination [%s] is not empty\", defaultWorkspaceDir)\n\t}\n\n\tvar moves []workspaceDirMove\n\tfor _, name := range legacyIOSWorkspaceEntries {\n\t\tfrom := filepath.Join(workspaceBaseDir, name)\n\t\tif _, statErr := os.Lstat(from); statErr != nil {\n\t\t\tif errors.Is(statErr, fs.ErrNotExist) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn false, fmt.Errorf(\"stat source [%s] failed: %w\", from, statErr)\n\t\t}\n\n\t\tto := filepath.Join(defaultWorkspaceDir, name)\n\t\tif _, statErr := os.Lstat(to); statErr == nil {\n\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)","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/working_mobile.go#L170-L206","documentation":"During legacy iOS workspace migration, each known legacy directory is checked with os.Lstat before being renamed into the new default workspace. If the Lstat fails with an error other than NotExist (the destination already existing is handled separately), migration aborts and wraps the stat error with the destination path. This guards against ambiguous filesystem states where the mover cannot tell whether the destination is safe to write.","triggerScenarios":"migrateLegacyIOSWorkspace calls os.Lstat(to) for a destination path under defaultWorkspaceDir and the returned error is neither nil (exists) nor fs.ErrNotExist — e.g. a permission error on a parent directory of the destination, an I/O error, or a symlink loop in the path.","commonSituations":"Restored or partially synced workspace where the destination path exists but is unreadable; macOS/iOS app-container permission changes after an OS upgrade; a corrupted or locked parent directory on the volume; antivirus or backup software holding the directory open.","solutions":["Check the wrapped statErr (%w) to identify the underlying cause (permission, I/O, symlink loop) and fix that condition","Verify the app has read permission on the new workspace directory and its parents; repair with chown/chmod or reinstall the app container","If a stale entry sits at the destination, remove or rename it manually, then relaunch so migration re-runs","If the volume is failing or unmountable, restore the workspace from sync/backup to a healthy location"],"exampleFix":"// before: migration aborts on unexpected stat error\nif _, statErr := os.Lstat(to); statErr == nil {\n    return false, fmt.Errorf(\"destination [%s] already exists\", to)\n} else if !errors.Is(statErr, fs.ErrNotExist) {\n    return false, fmt.Errorf(\"stat destination [%s] failed: %w\", to, statErr)\n}\n// after: pre-check the parent directory is traversable before migrating\nif dirErr := os.Chdir(filepath.Dir(to)); dirErr != nil {\n    logging.LogErrorf(\"workspace dir [%s] not accessible: %v\", filepath.Dir(to), dirErr)\n    return false, dirErr\n}","handlingStrategy":"try-catch","validationCode":"for _, name := range knownEntries {\n    to := filepath.Join(defaultWorkspaceDir, name)\n    if _, err := os.Lstat(to); err == nil {\n        // destination already exists — resolve manually before launching\n        continue\n    } else if !errors.Is(err, fs.ErrNotExist) {\n        // pre-flight: parent must be statable and writable\n        if _, derr := os.Stat(filepath.Dir(to)); derr != nil {\n            return fmt.Errorf(\"workspace dir [%s] not accessible: %w\", filepath.Dir(to), derr)\n        }\n    }\n}","typeGuard":"func statProblem(err error) bool {\n    return err != nil && !errors.Is(err, fs.ErrNotExist)\n}","tryCatchPattern":"moved, err := migrateLegacyIOSWorkspace(...)\nif err != nil {\n    var statErr *fs.PathError\n    if errors.As(err, &statErr) {\n        logging.LogErrorf(\"check permissions/path of [%s]: %v\", statErr.Path, statErr.Err)\n    }\n    return err\n}","preventionTips":["Keep the app container/workspace path writable and free of symlink loops","Do not place files or directories at the new workspace's expected entry names before upgrading","Exclude workspace directories from antivirus/backup real-time scanning during app startup","Check free disk space and volume health on the iOS device before upgrading"],"tags":["filesystem","migration","ios","stat","workspace"],"backgroundTag":"file-not-found","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"}