MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / buildArchive

Function buildArchive

pkg/cmd/package/support/pack.go:194–255  ·  view source on GitHub ↗
(out io.Writer, outFilePath string, basePath string, filesToArchive []string, isVerbose bool)

Source from the content-addressed store, hash-verified

192}
193
194func buildArchive(out io.Writer, outFilePath string, basePath string, filesToArchive []string, isVerbose bool) (*os.File, error) {
195 _, outFile := filepath.Split(outFilePath)
196 zipFile, err := os.Create(outFilePath)
197 if err != nil {
198 return nil, err
199 }
200 defer zipFile.Close()
201
202 writer := zip.NewWriter(zipFile)
203 defer writer.Close()
204
205 for _, path := range filesToArchive {
206 if path == outFile || path == "." {
207 continue
208 }
209
210 fullPath := filepath.Join(basePath, path)
211 fileInfo, err := os.Stat(fullPath)
212 if err != nil {
213 return nil, err
214 }
215
216 header, err := zip.FileInfoHeader(fileInfo)
217 if err != nil {
218 return nil, err
219 }
220
221 header.Method = zip.Deflate
222 header.Name = path
223 if fileInfo.IsDir() {
224 header.Name += "/"
225 }
226
227 headerWriter, err := writer.CreateHeader(header)
228 if err != nil {
229 return nil, err
230 }
231
232 if fileInfo.IsDir() {
233 continue
234 }
235
236 f, err := os.Open(fullPath)
237 if err != nil {
238 return nil, err
239 }
240
241 _, err = io.Copy(headerWriter, f)
242 if err == nil {
243 VerboseOut(out, isVerbose, "Added file: %s\n", path)
244 } else {
245 return nil, err
246 }
247
248 err = f.Close()
249 if err != nil {
250 return nil, err
251 }

Callers 1

BuildPackageFunction · 0.85

Calls 2

VerboseOutFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected