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() {
archive, err := zip.OpenReader(archiveFileName)
if err != nil {
printError(fmt.Errorf("open %q: %v", archiveFileName, err))
exitNotFound()
notFoundError(fmt.Errorf("open %q: %v", archiveFileName, err))
}
defer archive.Close()
file := findFileInZip(fileName, &archive.Reader)
if file == nil {
printError(fmt.Errorf("find %q in %q: not found", fileName, archiveFileName))
exitNotFound()
notFoundError(fmt.Errorf("find %q in %q: not found", fileName, archiveFileName))
}
// Start decompressing the file
reader, err := file.Open()
......@@ -83,7 +81,7 @@ func fatalError(err error) {
os.Exit(1)
}
func exitNotFound() {
fmt.Printf("%d\n", -zipartifacts.StatusEntryNotFound) // for the content-length reader
func notFoundError(err error) {
printError(err)
os.Exit(zipartifacts.StatusEntryNotFound)
}
......@@ -17,8 +17,6 @@ import (
"syscall"
)
var notFoundString = fmt.Sprintf("%d", -zipartifacts.StatusEntryNotFound)
func detectFileContentType(fileName string) string {
contentType := mime.TypeByExtension(filepath.Ext(fileName))
if contentType == "" {
......@@ -50,12 +48,12 @@ func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Hea
reader := bufio.NewReader(stdout)
contentLength, err := reader.ReadString('\n')
if err != nil {
if catFileErr := waitCatFile(catFile); catFileErr != nil {
return catFileErr
}
return fmt.Errorf("read content-length: %v", err)
}
contentLength = strings.TrimSuffix(contentLength, "\n")
if contentLength == notFoundString {
return os.ErrNotExist
}
// Write http headers about the file
headers.Set("Content-Length", contentLength)
......@@ -66,15 +64,20 @@ func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Hea
return fmt.Errorf("copy %v stdout: %v", catFile.Args, err)
}
if err := catFile.Wait(); err != nil {
if st, ok := helper.ExitStatus(err); ok && st == zipartifacts.StatusEntryNotFound {
return os.ErrNotExist
return waitCatFile(catFile)
}
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
......
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