Skip to content

Commit

Permalink
Count unzipped files
Browse files Browse the repository at this point in the history
In case no files were unzipped, program is exited and suggests that user
provided incorrect filter type.
  • Loading branch information
ondrowan committed May 4, 2018
1 parent 286e4e4 commit 5efda7a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ func main() {
}

tmpArchivePath := createTmpArchive(zipFile)
unzipArchive(tmpArchivePath, filterType)
unzippedFileCount := unzipArchive(tmpArchivePath, filterType)

if unzippedFileCount > 0 {
fmt.Fprintf(os.Stdout, "%d files were unzipped.\n", unzippedFileCount)
} else {
exit(1, fmt.Sprintf("No files were unzipped. Is \"%s\" correct filter type?", filterType))
}

writeToDotfile(*release.TagName)
showReleaseNotes(release)

Expand Down Expand Up @@ -126,7 +133,7 @@ func createTmpArchive(content io.ReadCloser) string {
return tmpfile.Name()
}

func unzipArchive(path string, filterType string) {
func unzipArchive(path string, filterType string) int {
archiveReader, err := zip.OpenReader(path)

if err != nil {
Expand All @@ -147,11 +154,16 @@ func unzipArchive(path string, filterType string) {
}
}

copiedFiles := 0

for _, archiveFile := range archiveReader.File {
if strings.HasSuffix(archiveFile.Name, ".filter") && fileFilter(archiveFile) {
copyFileContent(archiveFile, poePath)
copiedFiles++
}
}

return copiedFiles
}

func filterTypeToFolder(filterType string) string {
Expand Down

0 comments on commit 5efda7a

Please sign in to comment.