Skip to content

Commit

Permalink
Don't use an fd at all in dontHash mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDiscordian committed Jun 2, 2021
1 parent 7a9f8d1 commit a59bd8a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ func (fh *FileHash) Recalculate(PathOnDisk string, dontHash bool) *FileHash {
}

func GetHashValue(fpath string, dontHash bool) []byte {
f, err := os.Open(fpath)
if err != nil {
return nil
}
defer f.Close()
if !dontHash {
f, err := os.Open(fpath)
if err != nil {
return nil
}
hash := xxhash.New()
if _, err := io.Copy(hash, f); err != nil {
f.Close()
return nil
}
f.Close()
return hash.Sum(nil)
} else {
fi, err := f.Stat()
fi, err := os.Stat(fpath)
if err != nil {
return nil
}
Expand Down

0 comments on commit a59bd8a

Please sign in to comment.