yorukot/superfile · error
failed to create destination file: %w
Error message
failed to create destination file: %w
What it means
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.
Source
Thrown at src/internal/file_operations.go:146
}
return os.Symlink(target, dst)
}
func isSymlink(info os.FileInfo) bool {
return info.Mode()&os.ModeSymlink != 0
}
// copyFile copies a single file
func copyFile(src, dst string, srcInfo os.FileInfo) error {
srcFile, err := os.Open(src)
if err != nil {
return fmt.Errorf("failed to open source file: %w", err)
}
defer srcFile.Close()
dstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, srcInfo.Mode())
if err != nil {
return fmt.Errorf("failed to create destination file: %w", err)
}
defer dstFile.Close()
if _, err := io.Copy(dstFile, srcFile); err != nil {
return fmt.Errorf("failed to copy file contents: %w", err)
}
return nil
}
// pasteDir handles directory copying with progress tracking
func pasteDir(src, dst string, p *processbar.Process, cut bool, processBarModel *processbar.Model) error {
dst, err := renameIfDuplicate(dst)
if err != nil {
return err
}
// Check if we can do a fast move within the same partition
sameDev, err := isSamePartition(src, dst)View on GitHub (pinned to b72f550bc6)
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.
Example fix
// before
err := ops.CopyFile(srcPath, dstPath)
// after
if err := os.MkdirAll(filepath.Dir(dstPath), 0o755); err != nil {
return err
}
if info, err := os.Stat(dstPath); err == nil && info.IsDir() {
return fmt.Errorf("%s is a directory; pick a different target name", dstPath)
}
return ops.CopyFile(srcPath, dstPath) Defensive patterns
Strategy: validation
Validate before calling
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
return err
}
if info, err := os.Stat(dst); err == nil && info.IsDir() {
return fmt.Errorf("target %s is a directory", dst)
}
if !writableDir(filepath.Dir(dst)) {
return fmt.Errorf("destination dir %s is not writable", filepath.Dir(dst))
} Try / catch
if err := ops.CopyFile(src, dst); err != nil {
if errors.Is(err, fs.ErrPermission) { /* chmod/chown or pick another target */ }
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to create destination directory: %w
- failed to read source directory: %w
- failed to get entry info: %w
- failed to open source file: %w
- failed to copy file contents: %w
AI-assisted analysis of yorukot/superfile@b72f550bc6 (2026-09-01).
Data as JSON: /api/errors/76a13e770326e197.
Report an issue: GitHub.