Skip to content

Commit

Permalink
RenameCrossDevice better handles 0 byte files.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Jul 5, 2024
1 parent f93d2c8 commit 2c40744
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/helper/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,13 @@ func RenameCrossDevice(oldpath, newpath string) error {
if _, err = io.Copy(dst, src); err != nil {
return fmt.Errorf("rename cross device copy %w", err)
}
fi, err := os.Stat(oldpath)
if err != nil || fi.Size() == 0 {
if fi, err := os.Stat(oldpath); err != nil {
defer os.Remove(newpath)
return fmt.Errorf("rename cross device stat %w", err)
} else if fi.Size() == 0 {
defer os.Remove(newpath)
defer os.Remove(oldpath)
return fmt.Errorf("rename cross device empty file, %w", os.ErrNotExist)
}
defer os.Remove(oldpath)
return nil
Expand Down

0 comments on commit 2c40744

Please sign in to comment.