From f8f28eec5163071841e7217779d301eb6e4bfbe0 Mon Sep 17 00:00:00 2001 From: barnettZQG Date: Mon, 4 Jun 2018 15:42:05 +0800 Subject: [PATCH] [FIX] fix restore bug --- builder/exector/groupapp_restore.go | 4 ++-- util/comman.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/builder/exector/groupapp_restore.go b/builder/exector/groupapp_restore.go index 0fd402a14..8ac91c471 100644 --- a/builder/exector/groupapp_restore.go +++ b/builder/exector/groupapp_restore.go @@ -522,7 +522,7 @@ func (b *BackupAPPRestore) downloadFromLocal(backup *dbmodel.AppBackup) error { logrus.Errorf("unzip file error when restore backup app , %s", err.Error()) return err } - dirs, err := util.GetDirList(b.cacheDir, 1) + dirs, err := util.GetDirNameList(b.cacheDir, 1) if err != nil || len(dirs) < 1 { b.Logger.Error(util.Translation("unzip metadata file error"), map[string]string{"step": "backup_builder", "status": "failure"}) return fmt.Errorf("find metadata cache dir error after unzip file") @@ -551,7 +551,7 @@ func (b *BackupAPPRestore) downloadFromFTP(backup *dbmodel.AppBackup) error { logrus.Errorf("unzip file error when restore backup app , %s", err.Error()) return err } - dirs, err := util.GetDirList(b.cacheDir, 1) + dirs, err := util.GetDirNameList(b.cacheDir, 1) if err != nil || len(dirs) < 1 { b.Logger.Error(util.Translation("unzip metadata file error"), map[string]string{"step": "backup_builder", "status": "failure"}) return fmt.Errorf("find metadata cache dir error after unzip file") diff --git a/util/comman.go b/util/comman.go index f5d93f0a6..b1c67a562 100644 --- a/util/comman.go +++ b/util/comman.go @@ -542,3 +542,26 @@ func GetDirList(dirpath string, level int) ([]string, error) { } return dirlist, nil } + +// GetDirNameList get all lower level dir +func GetDirNameList(dirpath string, level int) ([]string, error) { + var dirlist []string + list, err := ioutil.ReadDir(dirpath) + if err != nil { + return nil, err + } + for _, f := range list { + if f.IsDir() { + if level <= 1 { + dirlist = append(dirlist, f.Name()) + } else { + list, err := GetDirList(filepath.Join(dirpath, f.Name()), level-1) + if err != nil { + return nil, err + } + dirlist = append(dirlist, list...) + } + } + } + return dirlist, nil +}