Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hash add file size limit #48

Merged
merged 8 commits into from
Jul 18, 2022
Merged
12 changes: 11 additions & 1 deletion plugin/driver/eBPF/user/cache/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ func (h *HashCache) Get(path string) string {
return fileHash.hash
}
fileHash.updateTime()
// if it's not in cache, check the stat
// if it's less time, check the stat
stat, err = getStat(path)
if err != nil {
fileHash.hash = share.INVALID_STRING
return fileHash.hash
}
// file size limit
if stat.Size > maxFileSize {
fileHash.hash = share.INVALID_STRING
return fileHash.hash
}
// if stat is invalid, get the hash and update all
if fileHash.statInvalid(stat.Ino, stat.Mtim.Sec, stat.Size) {
fileHash.hash = genHash(path)
Expand All @@ -74,6 +79,11 @@ func (h *HashCache) Get(path string) string {
fileHash.hash = share.INVALID_STRING
return fileHash.hash
}
// file size limit
if stat.Size > maxFileSize {
fileHash.hash = share.INVALID_STRING
return fileHash.hash
}
fileHash.hash = genHash(path)
fileHash.updateStat(stat)
return fileHash.hash
Expand Down