MCPcopy Create free account
hub / github.com/MertJSX/folderhost / extractFile

Function extractFile

utils/archive_functions.go:55–93  ·  view source on GitHub ↗
(file *zip.File, dest string, totalSize *int64, uid int, gid int)

Source from the content-addressed store, hash-verified

53}
54
55func extractFile(file *zip.File, dest string, totalSize *int64, uid int, gid int) error {
56 filePath := filepath.Join(dest, file.Name)
57
58 if !IsSafePath(filePath) {
59 return fmt.Errorf("security risk: wrong filepath")
60 }
61
62 if file.FileInfo().IsDir() {
63 err := os.MkdirAll(filePath, 0755)
64 if err != nil {
65 return err
66 }
67 // Windows specific error handling :D
68 if runtime.GOOS != "windows" {
69 return os.Chown(filePath, uid, gid)
70 }
71 return nil
72 }
73
74 if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
75 return err
76 }
77
78 outFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
79 if err != nil {
80 return err
81 }
82 defer outFile.Close()
83
84 rc, err := file.Open()
85 if err != nil {
86 return err
87 }
88 defer rc.Close()
89
90 size, err := io.Copy(outFile, rc)
91 *totalSize += size
92 return err
93}
94
95func Zip(src, dest string, cb func(int64, bool, string)) error {
96 _, err := os.Stat(src)

Callers 1

UnzipFunction · 0.85

Calls 1

IsSafePathFunction · 0.85

Tested by

no test coverage detected