(out io.Writer, outFilePath string, basePath string, filesToArchive []string, isVerbose bool)
| 192 | } |
| 193 | |
| 194 | func 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 | } |
no test coverage detected