in cli_tools/diagnostics/main.go [45:90]
func zipFiles(logs []logFolder, outputPath string) (err error) {
newFile, err := os.Create(outputPath)
if err != nil {
return err
}
defer func() {
// This takes priority over the non-fatal errors
if cErr := newFile.Close(); cErr != nil && (err == nil || err == errNonFatal) {
err = cErr
}
}()
writer := zip.NewWriter(newFile)
defer writer.Close()
err = nil
for _, folder := range logs {
for _, path := range folder.files {
file, zErr := os.Open(path)
if zErr != nil {
log.Printf("Error opening file %s for zipping with error %v\n", path, err)
err = errNonFatal
continue
}
defer func() {
if cErr := file.Close(); cErr != nil {
err = errNonFatal
}
}()
p := fmt.Sprintf("%s/%s", folder.name, filepath.Base(path))
zf, zErr := writer.Create(p)
if zErr != nil {
log.Printf("Error saving file %s to zip with error %v\n", path, err)
err = errNonFatal
continue
}
if _, zErr = io.Copy(zf, file); zErr != nil {
log.Printf("Error saving contents of file %s with error %v\n", path, err)
err = errNonFatal
}
}
}
return err
}