diff --git a/backend/utils/files/fileinfo.go b/backend/utils/files/fileinfo.go index 224e95296..102450d3f 100644 --- a/backend/utils/files/fileinfo.go +++ b/backend/utils/files/fileinfo.go @@ -64,6 +64,20 @@ type FileSearchInfo struct { fs.FileInfo } +func getDirSize(fs afero.Fs, path string) (int64, error) { + var size int64 + err := afero.Walk(fs, path, func(p string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() { + size += info.Size() + } + return nil + }) + return size, err +} + func NewFileInfo(op FileOption) (*FileInfo, error) { var appFs = afero.NewOsFs() @@ -101,6 +115,11 @@ func NewFileInfo(op FileOption) (*FileInfo, error) { } if op.Expand { if file.IsDir { + size, err := getDirSize(appFs, op.Path) + if err != nil { + return nil, err + } + file.Size = size if err := file.listChildren(op); err != nil { return nil, err } diff --git a/frontend/src/views/host/file-management/detail/index.vue b/frontend/src/views/host/file-management/detail/index.vue index 9a61fbf8a..1d397842d 100644 --- a/frontend/src/views/host/file-management/detail/index.vue +++ b/frontend/src/views/host/file-management/detail/index.vue @@ -10,7 +10,15 @@ {{ data.type }} {{ data.path }} - {{ computeSize(data.size) }} + + + + {{ $t('file.calculate') }} + + {{ computeSize(data.dirSize) }} + + + {{ computeSize(data.size) }} {{ data.mode }} {{ data.user }} @@ -25,7 +33,7 @@