[FIX] fix restore bug

This commit is contained in:
barnettZQG 2018-06-04 15:42:05 +08:00
parent 4097ff78c2
commit f8f28eec51
2 changed files with 25 additions and 2 deletions

View File

@ -522,7 +522,7 @@ func (b *BackupAPPRestore) downloadFromLocal(backup *dbmodel.AppBackup) error {
logrus.Errorf("unzip file error when restore backup app , %s", err.Error()) logrus.Errorf("unzip file error when restore backup app , %s", err.Error())
return err return err
} }
dirs, err := util.GetDirList(b.cacheDir, 1) dirs, err := util.GetDirNameList(b.cacheDir, 1)
if err != nil || len(dirs) < 1 { if err != nil || len(dirs) < 1 {
b.Logger.Error(util.Translation("unzip metadata file error"), map[string]string{"step": "backup_builder", "status": "failure"}) 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") 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()) logrus.Errorf("unzip file error when restore backup app , %s", err.Error())
return err return err
} }
dirs, err := util.GetDirList(b.cacheDir, 1) dirs, err := util.GetDirNameList(b.cacheDir, 1)
if err != nil || len(dirs) < 1 { if err != nil || len(dirs) < 1 {
b.Logger.Error(util.Translation("unzip metadata file error"), map[string]string{"step": "backup_builder", "status": "failure"}) 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") return fmt.Errorf("find metadata cache dir error after unzip file")

View File

@ -542,3 +542,26 @@ func GetDirList(dirpath string, level int) ([]string, error) {
} }
return dirlist, nil 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
}