mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 02:38:17 +08:00
[FIX] fix restore app data bug, if have same volume parent dir
This commit is contained in:
parent
08ebb30f64
commit
c9380f2740
@ -229,6 +229,11 @@ func (b *BackupAPPRestore) restoreVersionAndData(backup *dbmodel.AppBackup, appS
|
||||
}
|
||||
err := util.Rename(tmpDir, util.GetParentDirectory(app.Service.HostPath))
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "file exists") {
|
||||
if err := util.MergeDir(tmpDir, util.GetParentDirectory(app.Service.HostPath)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
if err := os.Chmod(app.Service.HostPath, 0777); err != nil {
|
||||
|
@ -513,6 +513,20 @@ func Rename(old, new string) error {
|
||||
return os.Rename(old, new)
|
||||
}
|
||||
|
||||
//MergeDir MergeDir
|
||||
func MergeDir(fromdir, todir string) error {
|
||||
files, err := ioutil.ReadDir(fromdir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range files {
|
||||
if err := os.Rename(path.Join(fromdir, f.Name()), path.Join(todir, f.Name())); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//CreateVersionByTime create version number
|
||||
func CreateVersionByTime() string {
|
||||
now := time.Now()
|
||||
|
@ -74,3 +74,9 @@ func TestGetDirList(t *testing.T) {
|
||||
}
|
||||
t.Log(list)
|
||||
}
|
||||
|
||||
func TestMergeDir(t *testing.T) {
|
||||
if err := MergeDir("/tmp/ctr-944254844/", "/tmp/cache"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user