MCPcopy Create free account
hub / github.com/cli/cli / writeTarGzip

Function writeTarGzip

script/ghmock/archive.go:88–155  ·  view source on GitHub ↗
(w io.Writer, root string)

Source from the content-addressed store, hash-verified

86}
87
88func writeTarGzip(w io.Writer, root string) error {
89 root, err := filepath.EvalSymlinks(root)
90 if err != nil {
91 return err
92 }
93 root, err = filepath.Abs(root)
94 if err != nil {
95 return err
96 }
97 gz := gzip.NewWriter(w)
98 tw := tar.NewWriter(gz)
99 walkErr := filepath.WalkDir(root, func(path string, entry fs.DirEntry, walkErr error) error {
100 if walkErr != nil || path == root {
101 return walkErr
102 }
103 rel, err := filepath.Rel(root, path)
104 if err != nil {
105 return err
106 }
107 info, err := entry.Info()
108 if err != nil {
109 return err
110 }
111 link := ""
112 if info.Mode()&os.ModeSymlink != 0 {
113 link, err = os.Readlink(path)
114 if err != nil {
115 return err
116 }
117 if filepath.IsAbs(link) && pathWithin(root, link) {
118 link, err = filepath.Rel(filepath.Dir(path), link)
119 if err != nil {
120 return err
121 }
122 }
123 }
124 header, err := tar.FileInfoHeader(info, filepath.ToSlash(link))
125 if err != nil {
126 return err
127 }
128 header.Name = filepath.ToSlash(rel)
129 var data []byte
130 if info.Mode().IsRegular() && strings.HasPrefix(header.Name, "git/") && isGitPathFile(header.Name) {
131 data, err = portableGitPath(path, root)
132 if err != nil {
133 return err
134 }
135 header.Size = int64(len(data))
136 }
137 if err := tw.WriteHeader(header); err != nil {
138 return err
139 }
140 if data != nil {
141 _, err := tw.Write(data)
142 return err
143 }
144 if !info.Mode().IsRegular() {
145 return nil

Callers 1

writeExportArchiveFunction · 0.85

Calls 9

pathWithinFunction · 0.85
isGitPathFileFunction · 0.85
portableGitPathFunction · 0.85
ModeMethod · 0.80
OpenMethod · 0.80
JoinMethod · 0.80
WriteMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected