{"record":{"id":"075febb6165065f0","repo":"siyuan-note/siyuan","slug":"stat-source-s-failed-w","errorCode":null,"errorMessage":"stat source [%s] failed: %w","messagePattern":"stat source \\[(.+?)\\] failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/working_mobile.go","lineNumber":181,"sourceCode":"\t}\n\n\tdefaultWorkspaceDir := filepath.Join(workspaceBaseDir, \"siyuan\")\n\tdestinationEntries, readErr := os.ReadDir(defaultWorkspaceDir)\n\tif readErr != nil {\n\t\treturn false, fmt.Errorf(\"read destination [%s] failed: %w\", defaultWorkspaceDir, readErr)\n\t}\n\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 {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/working_mobile.go#L163-L199","documentation":"For each legacy iOS workspace entry, migrateLegacyIOSWorkspace calls os.Lstat on the source path. If stat fails for a reason other than not-exist (skipped intentionally), it returns \"stat source [<path>] failed: <cause>\".","triggerScenarios":"A legacy entry exists but cannot be statted — permission denied in the sandbox, broken symlink resolution, or I/O errors on the container volume.","commonSituations":"OS revoked file access after an update, corrupted legacy directory entries, files locked by another process during iOS backup/restore.","solutions":["Check the wrapped cause for permission vs I/O errors","Restore sandbox file access permissions for the app container","Remove or repair the broken legacy entry that fails to stat","Retry migration after device storage becomes healthy"],"exampleFix":"// before\nreturn false, fmt.Errorf(\"stat source [%s] failed: %w\", from, statErr)\n// after: log and skip unreadable entries instead of aborting the whole migration\nlogging.LogErrorf(\"stat source [%s] failed: %v\", from, statErr)\ncontinue","handlingStrategy":"try-catch","validationCode":"// stat each legacy entry and report unreadable ones up front\nfor _, name := range legacyEntries {\n\tif _, err := os.Lstat(filepath.Join(base, name)); err != nil && !os.IsNotExist(err) {\n\t\t// resolve permissions/IO before migrating\n\t}\n}","typeGuard":null,"tryCatchPattern":"migrated, err := migrateLegacyIOSWorkspace(...)\nif err != nil && strings.HasPrefix(err.Error(), \"stat source\") {\n\t// restore file access, repair or skip the offending entry, then retry\n}","preventionTips":["Preserve app sandbox file-access entitlements across updates","Avoid modifying legacy workspace entries during migration","Back up legacy entries before running migration"],"tags":["ios","migration","filesystem","stat"],"backgroundTag":"file-read-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"}