Don't fallback between compression methods available unless we get strictly HTTP 404. #129 #125

Prior to that, some real errors could have been masked away by that fallback.
This commit is contained in:
Andrey Smirnov
2014-10-24 08:51:04 +04:00
parent d2d21c3df7
commit 7be2ef8b85
3 changed files with 39 additions and 29 deletions
+17 -3
View File
@@ -16,6 +16,17 @@ import (
"strings"
)
// HTTPError is download error connected to HTTP code
type HTTPError struct {
Code int
URL string
}
// Error
func (e *HTTPError) Error() string {
return fmt.Sprintf("HTTP code %d while fetching %s", e.Code, e.URL)
}
// Check interface
var (
_ aptly.Downloader = (*downloaderImpl)(nil)
@@ -139,7 +150,7 @@ func (downloader *downloaderImpl) handleTask(task *downloadTask) {
}
if resp.StatusCode < 200 || resp.StatusCode > 299 {
task.result <- fmt.Errorf("HTTP code %d while fetching %s", resp.StatusCode, task.url)
task.result <- &HTTPError{Code: resp.StatusCode, URL: task.url}
return
}
@@ -307,13 +318,16 @@ func DownloadTryCompression(downloader aptly.Downloader, url string, expectedChe
}
if err != nil {
continue
if err1, ok := err.(*HTTPError); ok && err1.Code == 404 {
continue
}
return nil, nil, err
}
var uncompressed io.Reader
uncompressed, err = method.transformation(file)
if err != nil {
continue
return nil, nil, err
}
return uncompressed, file, err