@ -160,24 +160,25 @@ const notRegularFileMode = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | o
// getDirectorySize returns the disk consumption for a given path
// getDirectorySize returns the disk consumption for a given path
func getDirectorySize ( path string ) ( int64 , error ) {
func getDirectorySize ( path string ) ( int64 , error ) {
var size int64
var size int64
err := filepath . WalkDir ( path , func ( _ string , info os . DirEntry , err error ) error {
err := filepath . WalkDir ( path , func ( _ string , entry os . DirEntry , err error ) error {
if err != nil {
if os . IsNotExist ( err ) { // ignore the error because some files (like temp/lock file) may be deleted during traversing.
if os . IsNotExist ( err ) { // ignore the error because the file maybe deleted during traversing.
return nil
return nil
} else if err != nil {
}
return err
return err
}
}
if info . IsDir ( ) {
if entry . IsDir ( ) {
return nil
return nil
}
}
f , err := info . Info ( )
info , err := entry . Info ( )
if err != nil {
if os . IsNotExist ( err ) { // ignore the error as above
return nil
} else if err != nil {
return err
return err
}
}
if ( f. Mode ( ) & notRegularFileMode ) == 0 {
if ( in fo . Mode ( ) & notRegularFileMode ) == 0 {
size += f. Size ( )
size += in fo . Size ( )
}
}
return err
return nil
} )
} )
return size , err
return size , err
}
}