MCPcopy
hub / github.com/cli/cli / extractZipFile

Function extractZipFile

internal/zip/zip.go:42–73  ·  view source on GitHub ↗
(zf *zip.File, dest safepaths.Absolute)

Source from the content-addressed store, hash-verified

40}
41
42func extractZipFile(zf *zip.File, dest safepaths.Absolute) (extractErr error) {
43 zm := zf.Mode()
44 if zm.IsDir() {
45 extractErr = os.MkdirAll(dest.String(), dirMode)
46 return
47 }
48
49 var f io.ReadCloser
50 f, extractErr = zf.Open()
51 if extractErr != nil {
52 return
53 }
54 defer f.Close()
55
56 if extractErr = os.MkdirAll(filepath.Dir(dest.String()), dirMode); extractErr != nil {
57 return
58 }
59
60 var df *os.File
61 if df, extractErr = os.OpenFile(dest.String(), os.O_WRONLY|os.O_CREATE|os.O_EXCL, getPerm(zm)); extractErr != nil {
62 return
63 }
64
65 defer func() {
66 if err := df.Close(); extractErr == nil && err != nil {
67 extractErr = err
68 }
69 }()
70
71 _, extractErr = io.Copy(df, f)
72 return
73}
74
75func getPerm(m os.FileMode) os.FileMode {
76 if m&0111 == 0 {

Callers 1

ExtractZipFunction · 0.85

Calls 5

getPermFunction · 0.85
OpenMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.45
CopyMethod · 0.45

Tested by

no test coverage detected