siyuan-note/siyuan · warning
destination [ ] already exists
Error message
destination [%s] already exists
What it means
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.
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
Example fix
// before
if _, statErr := os.Lstat(to); statErr == nil {
return false, fmt.Errorf("destination [%s] already exists", to)
}
// after: treat pre-existing destination as already migrated
if _, statErr := os.Lstat(to); statErr == nil {
continue
} Defensive patterns
Strategy: validation
Validate before calling
// pre-check for destination conflicts before migrating
for _, name := range legacyEntries {
if _, err := os.Lstat(filepath.Join(destDir, name)); err == nil {
// conflict: resolve manually or mark as already migrated
}
} Try / catch
migrated, err := migrateLegacyIOSWorkspace(...)
if err != nil && strings.Contains(err.Error(), "already exists") {
// inspect the conflicting destination entry; remove stale leftover or skip
} Prevention
- 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
When it happens
Trigger: A file or directory with the same name as a legacy entry (e.g. 'data', 'conf') already exists inside <workspaceBaseDir>/siyuan when migration runs.
Common situations: Previous partial migration left some entries moved, the new workspace was initialized with default files before migration, or backup-restore recreated entries.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- destination [ ] is not empty
- move [ ] to [ ] failed
- read destination [ ] failed
- rollback [ ] to [ ] failed
- stat destination [ ] failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/f847f2cfb2e7e80b.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/working_mobile.go:186
return false, fmt.Errorf("read destination [%s] failed: %w", defaultWorkspaceDir, readErr)
}
if 0 < len(destinationEntries) {
return false, fmt.Errorf("destination [%s] is not empty", defaultWorkspaceDir)
}
var moves []workspaceDirMove
for _, name := range legacyIOSWorkspaceEntries {
from := filepath.Join(workspaceBaseDir, name)
if _, statErr := os.Lstat(from); statErr != nil {
if errors.Is(statErr, fs.ErrNotExist) {
continue
}
return false, fmt.Errorf("stat source [%s] failed: %w", from, statErr)
}
to := filepath.Join(defaultWorkspaceDir, name)
if _, statErr := os.Lstat(to); statErr == nil {
return false, fmt.Errorf("destination [%s] already exists", to)
} else if !errors.Is(statErr, fs.ErrNotExist) {
return false, fmt.Errorf("stat destination [%s] failed: %w", to, statErr)
}
moves = append(moves, workspaceDirMove{from: from, to: to})
}
var completed []workspaceDirMove
for _, move := range moves {
if renameErr := os.Rename(move.from, move.to); renameErr != nil {
var rollbackErrors []error
for i := len(completed) - 1; 0 <= i; i-- {
completedMove := completed[i]
if rollbackErr := os.Rename(completedMove.to, completedMove.from); rollbackErr != nil {
rollbackErrors = append(rollbackErrors, fmt.Errorf("rollback [%s] to [%s] failed: %w",
completedMove.to, completedMove.from, rollbackErr))
}
}
return false, errors.Join(append([]error{fmt.Errorf("move [%s] to [%s] failed: %w", move.from, move.to, renameErr)}, rollbackErrors...)...)View on GitHub (pinned to 9f775e8a12)