From 6260281cac924577bf8699ecf761e34c6a050bf1 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Mon, 12 Dec 2022 12:01:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=A4=87=E4=BB=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/app_utils.go | 3 ++- backend/utils/files/file_op.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 430734792..7e4b675a2 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -570,7 +570,8 @@ func getAppFromOss() error { } fileOp := files.NewFileOp() - if _, err := fileOp.Backup(appDir); err != nil { + + if _, err := fileOp.CopyAndBackup(appDir); err != nil { return err } diff --git a/backend/utils/files/file_op.go b/backend/utils/files/file_op.go index 6c6c61f82..5a036f973 100644 --- a/backend/utils/files/file_op.go +++ b/backend/utils/files/file_op.go @@ -433,5 +433,23 @@ func (f FileOp) Backup(srcFile string) (string, error) { if err := f.Rename(srcFile, backupPath); err != nil { return backupPath, err } + + return backupPath, nil +} + +func (f FileOp) CopyAndBackup(src string) (string, error) { + backupPath := src + "_bak" + info, _ := f.Fs.Stat(backupPath) + if info != nil { + if info.IsDir() { + _ = f.DeleteDir(backupPath) + } else { + _ = f.DeleteFile(backupPath) + } + } + _ = f.CreateDir(backupPath, 0755) + if err := f.Copy(src, backupPath); err != nil { + return backupPath, err + } return backupPath, nil }