{"record":{"id":"76a13e770326e197","repo":"yorukot/superfile","slug":"failed-to-create-destination-file-w","errorCode":null,"errorMessage":"failed to create destination file: %w","messagePattern":"failed to create destination file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations.go","lineNumber":146,"sourceCode":"\t}\n\treturn os.Symlink(target, dst)\n}\n\nfunc isSymlink(info os.FileInfo) bool {\n\treturn info.Mode()&os.ModeSymlink != 0\n}\n\n// copyFile copies a single file\nfunc copyFile(src, dst string, srcInfo os.FileInfo) error {\n\tsrcFile, err := os.Open(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open source file: %w\", err)\n\t}\n\tdefer srcFile.Close()\n\n\tdstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, srcInfo.Mode())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination file: %w\", err)\n\t}\n\tdefer dstFile.Close()\n\n\tif _, err := io.Copy(dstFile, srcFile); err != nil {\n\t\treturn fmt.Errorf(\"failed to copy file contents: %w\", err)\n\t}\n\treturn nil\n}\n\n// pasteDir handles directory copying with progress tracking\nfunc pasteDir(src, dst string, p *processbar.Process, cut bool, processBarModel *processbar.Model) error {\n\tdst, err := renameIfDuplicate(dst)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Check if we can do a fast move within the same partition\n\tsameDev, err := isSamePartition(src, dst)","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations.go#L128-L164","documentation":"copyFile wraps os.OpenFile(dst, O_WRONLY|O_CREATE|O_TRUNC, srcInfo.Mode()) failures when creating/truncating the destination file. The source mode is preserved; failure usually means the destination directory doesn't exist, lacks write permission, or dst is itself a directory.","triggerScenarios":"Pasting into a non-existent target directory; pasting onto a read-only mount or a path requiring root; target name collides with an existing directory; destination filesystem full may also surface here on create.","commonSituations":"Read-only volume or read-only bind mount; destination dir deleted between navigation and paste; copying a file over a path that is actually a directory (EISDIR); quota/permissions in shared folders.","solutions":["Ensure the destination directory exists (mkdir -p / filepath.MkdirAll) before pasting.","Add write permission to the destination directory (chmod u+w) or run as a user with rights.","Check the target path isn't an existing directory; choose a different name or remove the directory.","Check available space/quotas (df -h) and remount read-only volumes read-write."],"exampleFix":"// before\nerr := ops.CopyFile(srcPath, dstPath)\n// after\nif err := os.MkdirAll(filepath.Dir(dstPath), 0o755); err != nil {\n    return err\n}\nif info, err := os.Stat(dstPath); err == nil && info.IsDir() {\n    return fmt.Errorf(\"%s is a directory; pick a different target name\", dstPath)\n}\nreturn ops.CopyFile(srcPath, dstPath)","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {\n    return err\n}\nif info, err := os.Stat(dst); err == nil && info.IsDir() {\n    return fmt.Errorf(\"target %s is a directory\", dst)\n}\nif !writableDir(filepath.Dir(dst)) {\n    return fmt.Errorf(\"destination dir %s is not writable\", filepath.Dir(dst))\n}","typeGuard":null,"tryCatchPattern":"if err := ops.CopyFile(src, dst); err != nil {\n    if errors.Is(err, fs.ErrPermission) { /* chmod/chown or pick another target */ }\n    return err\n}","preventionTips":["Always MkdirAll the destination directory before pasting.","Check the target volume isn't mounted read-only.","Don't paste onto names that collide with existing directories."],"tags":["go","filesystem","copy","permissions"],"backgroundTag":"file-create-failed","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}