MCPcopy
hub / github.com/apache/devlake / createArchive

Function createArchive

backend/core/utils/io.go:56–89  ·  view source on GitHub ↗
(archiveType string, archivePath string, sourcePaths ...string)

Source from the content-addressed store, hash-verified

54}
55
56func createArchive(archiveType string, archivePath string, sourcePaths ...string) errors.Error {
57 for _, sourcePath := range sourcePaths {
58 relativeCopy := false
59 if strings.HasSuffix(sourcePath, "/*") {
60 sourcePath = sourcePath[0 : len(sourcePath)-2]
61 relativeCopy = true
62 }
63 srcPathAbs, err := filepath.Abs(sourcePath)
64 if err != nil {
65 return errors.Default.Wrap(err, fmt.Sprintf("error getting absolute path of %s", sourcePath))
66 }
67 archivePathAbs, err := filepath.Abs(archivePath)
68 if err != nil {
69 return errors.Default.Wrap(err, fmt.Sprintf("error getting absolute path of %s", archivePath))
70 }
71 srcInfo, err := os.Stat(srcPathAbs)
72 if err != nil {
73 return errors.Default.Wrap(err, fmt.Sprintf("error getting stats of path %s", srcPathAbs))
74 }
75 if relativeCopy && srcInfo.IsDir() {
76 err = copyContentsToArchive(archiveType, srcPathAbs, archivePathAbs)
77 } else {
78 if relativeCopy {
79 sourcePath = srcInfo.Name()
80 }
81 // directly copies over the src path as the dest path in the archive (can be improved later if needed to guard against abs paths)
82 err = copyToArchive(archiveType, srcPathAbs, archivePathAbs, sourcePath)
83 }
84 if err != nil {
85 return errors.Default.Wrap(err, "error trying to copy data to archive")
86 }
87 }
88 return nil
89}
90
91func copyContentsToArchive(archiveType string, absSourcePath string, absArchivePath string) errors.Error {
92 var files []os.DirEntry

Callers 2

CreateZipArchiveFunction · 0.85
CreateGZipArchiveFunction · 0.85

Calls 4

copyContentsToArchiveFunction · 0.85
copyToArchiveFunction · 0.85
WrapMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected