(archiveType string, archivePath string, sourcePaths ...string)
| 54 | } |
| 55 | |
| 56 | func 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 | |
| 91 | func copyContentsToArchive(archiveType string, absSourcePath string, absArchivePath string) errors.Error { |
| 92 | var files []os.DirEntry |
no test coverage detected