@@ -82,12 +82,12 @@ func shouldExtractPathInZip(pathPrefix string, zipPath *zip.File) bool {
8282}
8383
8484// Decompress the file at zipFileAbsPath and move only those files under filesToExtractFromZipPath to localPath
85- func extractFiles(zipFilePath, filesToExtractFromZipPath, localPath string) error {
85+ func extractFiles(zipFilePath, filesToExtractFromZipPath, localPath string) (int, error) {
8686
8787 // Open the zip file for reading.
8888 r, err := zip.OpenReader(zipFilePath)
8989 if err != nil {
90- return err
90+ return 0, err
9191 }
9292 defer r.Close()
9393
@@ -102,6 +102,9 @@ func extractFiles(zipFilePath, filesToExtractFromZipPath, localPath string) erro
102102 // Add the path from which we will extract files to the path prefix so we can exclude the appropriate files
103103 pathPrefix = filepath.Join(pathPrefix, filesToExtractFromZipPath)
104104
105+ // Count the number of files (not directories) unpacked
106+ fileCount := 0
107+
105108 // Iterate through the files in the archive,
106109 // printing some of their contents.
107110 for _, f := range r.File {
@@ -114,30 +117,31 @@ func extractFiles(zipFilePath, filesToExtractFromZipPath, localPath string) erro
114117 path := filepath.Join(localPath, strings.TrimPrefix(f.Name, pathPrefix))
115118 err = os.MkdirAll(path, 0777)
116119 if err != nil {
117- return fmt.Errorf("Failed to create local directory %s: %s", path, err)
120+ return fileCount, fmt.Errorf("Failed to create local directory %s: %s", path, err)
118121 }
119122 } else {
120123 // Read the file into a byte array
121124 readCloser, err := f.Open()
122125 if err != nil {
123- return fmt.Errorf("Failed to open file %s: %s", f.Name, err)
126+ return fileCount, fmt.Errorf("Failed to open file %s: %s", f.Name, err)
124127 }
125128
126129 byteArray, err := ioutil.ReadAll(readCloser)
127130 if err != nil {
128- return fmt.Errorf("Failed to read file %s: %s", f.Name, err)
131+ return fileCount, fmt.Errorf("Failed to read file %s: %s", f.Name, err)
129132 }
130133
131134 // Write the file
132135 err = ioutil.WriteFile(filepath.Join(localPath, strings.TrimPrefix(f.Name, pathPrefix)), byteArray, 0644)
133136 if err != nil {
134- return fmt.Errorf("Failed to write file: %s", err)
137+ return fileCount, fmt.Errorf("Failed to write file: %s", err)
135138 }
139+ fileCount++
136140 }
137141 }
138142 }
139143
140- return nil
144+ return fileCount, nil
141145}
142146
143147// Return an HTTP request that will fetch the given GitHub repo's zip file for the given tag, possibly with the gitHubOAuthToken in the header
0 commit comments