From 151f9d58d382932bfbf9726387403ba20be4308a Mon Sep 17 00:00:00 2001
From: John Bro <42930107+john1298308460@users.noreply.github.com>
Date: Wed, 26 Jun 2024 22:38:50 +0800
Subject: [PATCH] =?UTF-8?q?fit:=20=E6=96=87=E4=BB=B6=E5=B1=9E=E6=80=A7?=
=?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=A4=A7=E5=B0=8F=E5=80=BC=E8=B0=83=E6=95=B4?=
=?UTF-8?q?=20(#5575)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Refs #3934
---
backend/utils/files/fileinfo.go | 19 +++++++++++++
.../host/file-management/detail/index.vue | 27 +++++++++++++++++--
2 files changed, 44 insertions(+), 2 deletions(-)
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 @@