{"record":{"id":"ac33c883316092bd","repo":"juicedata/juicefs","slug":"s-already-exists","errorCode":null,"errorMessage":"%s already exists","messagePattern":"(.+?) already exists","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/clone.go","lineNumber":85,"sourceCode":"\tsrcPath := ctx.Args().Get(0)\n\tsrcAbsPath, err := filepath.Abs(srcPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"abs of %s: %s\", srcPath, err)\n\t}\n\tsrcIno, err := utils.GetFileInode(srcPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"lookup inode for %s: %s\", srcPath, err)\n\t}\n\tsrcParentIno, err := utils.GetFileInode(filepath.Dir(srcAbsPath))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"lookup inode for %s: %s\", filepath.Dir(srcAbsPath), err)\n\t}\n\tdst := ctx.Args().Get(1)\n\tif strings.HasSuffix(dst, string(filepath.Separator)) {\n\t\tdst = filepath.Join(dst, filepath.Base(srcPath))\n\t}\n\tif _, err := os.Stat(dst); err == nil {\n\t\treturn fmt.Errorf(\"%s already exists\", dst)\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"stat %s: %s\", dst, err)\n\t}\n\tdstAbsPath, err := filepath.Abs(dst)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"abs of %s: %s\", dst, err)\n\t}\n\n\tsrcMp, err := findMountpoint(srcAbsPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdstMp, err := findMountpoint(filepath.Dir(dstAbsPath))\n\tif err != nil {\n\t\treturn err\n\t}\n\tif srcMp != dstMp {\n\t\treturn fmt.Errorf(\"the clone DST path should be at the same mount point as the SRC path\")","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/clone.go#L67-L103","documentation":"Before cloning, clone checks the destination with os.Stat and rejects it with \"%s already exists\" if anything (file, directory, or symlink) already occupies the destination path. Note that if the destination ends with a separator, the source's base name is appended first, so the effective destination may differ from the argument typed.","triggerScenarios":"Running `juicefs clone <src> <dst>` where dst already exists; passing a trailing-slash destination directory that already contains a file with the source's base name; re-running a clone script without cleanup from a previous run.","commonSituations":"Retrying a failed clone without deleting the partial artifact; cloning into a directory that already holds the file; an automated pipeline re-executes the clone idempotently without a existence check.","solutions":["Remove or rename the existing destination before cloning.","Choose a fresh destination path (or append a timestamp/unique suffix).","If the destination is a directory, make sure it does not already contain a file named after the source's base name.","In scripts, guard with a test -e check or use clone's behavior to skip when it exists."],"exampleFix":"# before\njuicefs clone meta.sqlite3:0 /mnt/jfs/a /mnt/jfs/b   # /mnt/jfs/b exists\n# after\nrm /mnt/jfs/b\njuicefs clone meta.sqlite3:0 /mnt/jfs/a /mnt/jfs/b","handlingStrategy":"validation","validationCode":"dst := ctx.Args().Get(1)\nif strings.HasSuffix(dst, \"/\") {\n\tdst = filepath.Join(dst, filepath.Base(src))\n}\nif _, err := os.Stat(dst); err == nil {\n\treturn fmt.Errorf(\"destination %s exists; choose another\", dst)\n}","typeGuard":null,"tryCatchPattern":"if err := clone(ctx); err != nil && strings.HasSuffix(err.Error(), \"already exists\") {\n\t// pick a unique destination and retry\n\tnewDst := fmt.Sprintf(\"%s.%d\", ctx.Args().Get(1), time.Now().Unix())\n\tlog.Printf(\"retrying clone to %s\", newDst)\n}","preventionTips":["Generate unique destination names (timestamp/UUID suffix) in automation","Clean up partial clones before retrying a failed run","Remember trailing-slash destinations append the source base name — check for collisions there too"],"tags":["cli","filesystem","clone","path"],"backgroundTag":"file-already-exists","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}