Commit 7fb38099 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Stop passing errors on content-encoding line

parent e1222e92
...@@ -39,15 +39,13 @@ func main() { ...@@ -39,15 +39,13 @@ func main() {
archive, err := zip.OpenReader(archiveFileName) archive, err := zip.OpenReader(archiveFileName)
if err != nil { if err != nil {
printError(fmt.Errorf("open %q: %v", archiveFileName, err)) notFoundError(fmt.Errorf("open %q: %v", archiveFileName, err))
exitNotFound()
} }
defer archive.Close() defer archive.Close()
file := findFileInZip(fileName, &archive.Reader) file := findFileInZip(fileName, &archive.Reader)
if file == nil { if file == nil {
printError(fmt.Errorf("find %q in %q: not found", fileName, archiveFileName)) notFoundError(fmt.Errorf("find %q in %q: not found", fileName, archiveFileName))
exitNotFound()
} }
// Start decompressing the file // Start decompressing the file
reader, err := file.Open() reader, err := file.Open()
...@@ -83,7 +81,7 @@ func fatalError(err error) { ...@@ -83,7 +81,7 @@ func fatalError(err error) {
os.Exit(1) os.Exit(1)
} }
func exitNotFound() { func notFoundError(err error) {
fmt.Printf("%d\n", -zipartifacts.StatusEntryNotFound) // for the content-length reader printError(err)
os.Exit(zipartifacts.StatusEntryNotFound) os.Exit(zipartifacts.StatusEntryNotFound)
} }
...@@ -17,8 +17,6 @@ import ( ...@@ -17,8 +17,6 @@ import (
"syscall" "syscall"
) )
var notFoundString = fmt.Sprintf("%d", -zipartifacts.StatusEntryNotFound)
func detectFileContentType(fileName string) string { func detectFileContentType(fileName string) string {
contentType := mime.TypeByExtension(filepath.Ext(fileName)) contentType := mime.TypeByExtension(filepath.Ext(fileName))
if contentType == "" { if contentType == "" {
...@@ -50,12 +48,12 @@ func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Hea ...@@ -50,12 +48,12 @@ func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Hea
reader := bufio.NewReader(stdout) reader := bufio.NewReader(stdout)
contentLength, err := reader.ReadString('\n') contentLength, err := reader.ReadString('\n')
if err != nil { if err != nil {
if catFileErr := waitCatFile(catFile); catFileErr != nil {
return catFileErr
}
return fmt.Errorf("read content-length: %v", err) return fmt.Errorf("read content-length: %v", err)
} }
contentLength = strings.TrimSuffix(contentLength, "\n") contentLength = strings.TrimSuffix(contentLength, "\n")
if contentLength == notFoundString {
return os.ErrNotExist
}
// Write http headers about the file // Write http headers about the file
headers.Set("Content-Length", contentLength) headers.Set("Content-Length", contentLength)
...@@ -66,15 +64,20 @@ func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Hea ...@@ -66,15 +64,20 @@ func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Hea
return fmt.Errorf("copy %v stdout: %v", catFile.Args, err) return fmt.Errorf("copy %v stdout: %v", catFile.Args, err)
} }
if err := catFile.Wait(); err != nil { return waitCatFile(catFile)
if st, ok := helper.ExitStatus(err); ok && st == zipartifacts.StatusEntryNotFound { }
return os.ErrNotExist
} func waitCatFile(cmd *exec.Cmd) error {
err := cmd.Wait()
if err == nil {
return nil
}
return fmt.Errorf("wait for %v to finish: %v", catFile.Args, err) if st, ok := helper.ExitStatus(err); ok && st == zipartifacts.StatusEntryNotFound {
return os.ErrNotExist
} }
return fmt.Errorf("wait for %v to finish: %v", cmd.Args, err)
return nil
} }
// Artifacts downloader doesn't support ranges when downloading a single file // Artifacts downloader doesn't support ranges when downloading a single file
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment