forked from wal-g/wal-g
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not delete whole dir - clean it (wal-g#1767)
- Loading branch information
Showing
3 changed files
with
16 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |