updated restore backup warning message and changed archive.Extract to ignore irregular files

This commit is contained in:
Gani Georgiev
2024-03-17 15:43:27 +02:00
parent be40803d31
commit 48153d4542
36 changed files with 81 additions and 56 deletions
+7 -2
View File
@@ -9,7 +9,11 @@ import (
"strings"
)
// Extract extracts the zip archive at src to dest.
// Extract extracts the zip archive at "src" to "dest".
//
// Note that only dirs and regular files will be extracted.
// Symbolic links, named pipes, sockets, or any other irregular files
// are skipped because they come with too many edge cases and ambiguities.
func Extract(src, dest string) error {
zr, err := zip.OpenReader(src)
if err != nil {
@@ -46,11 +50,12 @@ func extractFile(zipFile *zip.File, basePath string) error {
}
defer r.Close()
// allow only dirs or regular files
if zipFile.FileInfo().IsDir() {
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return err
}
} else {
} else if zipFile.FileInfo().Mode().IsRegular() {
// ensure that the file path directories are created
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
return err