{"record":{"id":"f847f2cfb2e7e80b","repo":"siyuan-note/siyuan","slug":"destination-s-already-exists","errorCode":null,"errorMessage":"destination [%s] already exists","messagePattern":"destination \\[(.+?)\\] already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/util/working_mobile.go","lineNumber":186,"sourceCode":"\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 {\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...)...)","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/working_mobile.go#L168-L204","documentation":"When stattering the destination path for a legacy entry succeeds (the target already exists), migration aborts with \"destination [<path>] already exists\" to prevent overwriting existing workspace data.","triggerScenarios":"A file or directory with the same name as a legacy entry (e.g. 'data', 'conf') already exists inside <workspaceBaseDir>/siyuan when migration runs.","commonSituations":"Previous partial migration left some entries moved, the new workspace was initialized with default files before migration, or backup-restore recreated entries.","solutions":["Compare the existing destination entry with the legacy source and remove the stale one if it is a leftover from a partial migration","Rename or move conflicting entries manually, then re-run migration","Skip already-migrated entries (treat destination-exists as migrated) instead of failing","Only run migration before the new workspace is first initialized"],"exampleFix":"// before\nif _, statErr := os.Lstat(to); statErr == nil {\n\treturn false, fmt.Errorf(\"destination [%s] already exists\", to)\n}\n// after: treat pre-existing destination as already migrated\nif _, statErr := os.Lstat(to); statErr == nil {\n\tcontinue\n}","handlingStrategy":"validation","validationCode":"// pre-check for destination conflicts before migrating\nfor _, name := range legacyEntries {\n\tif _, err := os.Lstat(filepath.Join(destDir, name)); err == nil {\n\t\t// conflict: resolve manually or mark as already migrated\n\t}\n}","typeGuard":null,"tryCatchPattern":"migrated, err := migrateLegacyIOSWorkspace(...)\nif err != nil && strings.Contains(err.Error(), \"already exists\") {\n\t// inspect the conflicting destination entry; remove stale leftover or skip\n}","preventionTips":["Never run migration twice without cleaning up partial state","Skip entries whose destination already exists instead of aborting","Initialize the new default workspace only after migration completes"],"tags":["ios","migration","conflict","file-exists"],"backgroundTag":"file-already-exists","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"}