Skip to content

Commit

Permalink
Prevent fallback to slow path when the source file is completely empty
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Wiltink <sven@wiltink.dev>
  • Loading branch information
svenwiltink committed Aug 22, 2023
1 parent f1005bf commit bae7011
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sparse_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func detectDataSection(file *os.File, offset int64) (start int64, end int64, err

func supportsSeekHole(file *os.File) bool {
_, err := file.Seek(0, SEEK_DATA)
var syserr syscall.Errno

// when a file is completely empty SEEK_DATA fails with ENXIO indicating an EOF.
if errors.As(err, &syserr) {
if syserr == syscall.ENXIO {
return true
}
}
return err == nil
}

Expand Down

0 comments on commit bae7011

Please sign in to comment.