{"record":{"id":"214924d718b45700","repo":"rqlite/rqlite","slug":"destination-already-exists","errorCode":null,"errorMessage":"destination already exists","messagePattern":"destination already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/fsutil/copy.go","lineNumber":66,"sourceCode":"// interrupted copy to the same destination is removed first.\nfunc CopyDir(src string, dst string) error {\n\tsrc = filepath.Clean(src)\n\tdst = filepath.Clean(dst)\n\n\tsi, err := os.Stat(src)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !si.IsDir() {\n\t\treturn fmt.Errorf(\"source is not a directory\")\n\t}\n\n\t_, err = os.Stat(dst)\n\tif err != nil && !os.IsNotExist(err) {\n\t\treturn err\n\t}\n\tif err == nil {\n\t\treturn fmt.Errorf(\"destination already exists\")\n\t}\n\n\t// Stage the copy in a temporary directory next to the destination, clearing\n\t// out any remains of an earlier interrupted copy. The deferred removal is a\n\t// no-op once the rename below has succeeded.\n\ttmp := dst + tmpSuffix\n\tif err := os.RemoveAll(tmp); err != nil {\n\t\treturn err\n\t}\n\tdefer os.RemoveAll(tmp)\n\n\tif err := copyDir(src, tmp); err != nil {\n\t\treturn err\n\t}\n\tif err := os.Rename(tmp, dst); err != nil {\n\t\treturn err\n\t}\n\treturn SyncDirParentMaybe(dst)","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/rqlite/rqlite/blob/7586a4d1bdbd9a5a80021664c5a863cd850adb60/internal/fsutil/copy.go#L48-L84","documentation":"CopyDir refuses to run when the destination path already exists (os.Stat succeeds), since the copy is atomic via rename and would otherwise clobber existing data. The caller must remove or choose a new destination first.","triggerScenarios":"Thrown at internal/fsutil/copy.go:66 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the existing destination directory if it is safe to overwrite","Choose a fresh destination path","Clean up leftovers from a previous failed copy before retrying"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7586a4d1bdbd9a5a80021664c5a863cd850adb60","analyzedAt":"2026-09-03T07:03:02.260Z","contentChangedAt":"2026-09-03T07:03:02.260Z","schemaVersion":2},"datasetVersion":"2026-09-10T12:17:11.382Z"}