fsutil: Defensive check for Stat cast

This commit is contained in:
Łukasz Magiera 2021-01-19 18:53:37 +01:00 committed by GitHub
parent 834a6148b0
commit 560a127ce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,10 @@ func FileSize(path string) (SizeInfo, error) {
return err
}
if !info.IsDir() {
stat := info.Sys().(*syscall.Stat_t)
stat, ok := info.Sys().(*syscall.Stat_t)
if !ok {
return xerrors.New("FileInfo.Sys of wrong type")
}
// NOTE: stat.Blocks is in 512B blocks, NOT in stat.Blksize return SizeInfo{size}, nil
// See https://www.gnu.org/software/libc/manual/html_node/Attribute-Meanings.html