Skip to content

Commit 85f7f6f

Browse files
authored
Merge pull request #532 from GRFreire/folder-size-crash
Fix panic when trying to get folder size without needed permissions
2 parents c6370eb + 945aeab commit 85f7f6f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/internal/function.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,15 @@ func calculateMD5Checksum(filePath string) (string, error) {
415415
// Get directory total size
416416
func dirSize(path string) int64 {
417417
var size int64
418-
filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
418+
filepath.WalkDir(path, func(_ string, entry os.DirEntry, err error) error {
419419
if err != nil {
420420
outPutLog("Dir size function error", err)
421421
}
422-
if !info.IsDir() {
423-
size += info.Size()
422+
if !entry.IsDir() {
423+
info, err := entry.Info()
424+
if err == nil {
425+
size += info.Size()
426+
}
424427
}
425428
return err
426429
})

0 commit comments

Comments
 (0)