Skip to content

Commit

Permalink
do not delete whole dir - clean it (wal-g#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
kronwerk authored Aug 9, 2024
1 parent c99b165 commit 4020976
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/redis/rdb_backup_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var backupFetchCmd = &cobra.Command{
restoreCmd.Stderr = os.Stderr

dataPath, _ := conf.GetSetting(conf.RedisDataPath)
dataDir := archive.CreateFolderInfo(dataPath, os.FileMode(0750))
dataDir := archive.CreateFolderInfo(dataPath)
err = redis.HandleBackupFetch(ctx, storage.RootFolder(), args[0], restoreCmd, dataDir)
tracelog.ErrorLogger.FatalOnError(err)
},
Expand Down
3 changes: 1 addition & 2 deletions internal/databases/redis/aof_backup_fetch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package redis

import (
"context"
"os"
"path/filepath"

"github.com/wal-g/wal-g/internal"
Expand All @@ -20,7 +19,7 @@ func HandleAofFetchPush(
dataFolder, _ := conf.GetSetting(conf.RedisDataPath)
aofFolder, _ := conf.GetSetting(conf.RedisAppendonlyFolder)
aofPath := filepath.Join(dataFolder, aofFolder)
folder := archive.CreateFolderInfo(aofPath, os.FileMode(0750))
folder := archive.CreateFolderInfo(aofPath)

uploader, err := internal.ConfigureUploader()
if err != nil {
Expand Down
24 changes: 14 additions & 10 deletions internal/databases/redis/archive/fs.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
package archive

import (
"io/fs"
"os"
"path/filepath"
)

type FolderInfo struct {
Path string
fileMode fs.FileMode
Path string
}

func CreateFolderInfo(path string, fileMode fs.FileMode) *FolderInfo {
func CreateFolderInfo(path string) *FolderInfo {
return &FolderInfo{
Path: path,
fileMode: fileMode,
Path: path,
}
}

func (f *FolderInfo) CleanParent() error {
func (f *FolderInfo) CleanParent() (err error) {
parent := filepath.Dir(f.Path)
err := os.RemoveAll(parent)
starred := filepath.Join(parent, "*")
contents, err := filepath.Glob(starred)
if err != nil {
return err
return
}

return os.MkdirAll(f.Path, f.fileMode)
for _, item := range contents {
err = os.RemoveAll(item)
if err != nil {
return
}
}
return
}

0 comments on commit 4020976

Please sign in to comment.