diff --git a/pacoloco.go b/pacoloco.go index 7ed0607..e011dc7 100644 --- a/pacoloco.go +++ b/pacoloco.go @@ -229,11 +229,14 @@ func prefetchRequest(urlPath string, cachePath string) error { return err } if d != nil { - err = d.waitForCompletion() + err := d.waitForCompletion() d.decrementUsage() + if err != nil { + return err + } } - if err == nil && config.Prefetch != nil { + if config.Prefetch != nil { if !strings.HasSuffix(f.fileName, ".sig") && !strings.HasSuffix(f.fileName, ".db") { updateDBRequestedFile(f.repoName, f.fileName) // update info for prefetching } else if strings.HasSuffix(f.fileName, ".db") { @@ -241,7 +244,7 @@ func prefetchRequest(urlPath string, cachePath string) error { } } - return err + return nil } func handleRequest(w http.ResponseWriter, req *http.Request) error { @@ -278,7 +281,7 @@ func handleRequest(w http.ResponseWriter, req *http.Request) error { } } - if err == nil && config.Prefetch != nil { + if config.Prefetch != nil { if !strings.HasSuffix(f.fileName, ".sig") && !strings.HasSuffix(f.fileName, ".db") { updateDBRequestedFile(f.repoName, f.fileName) // update info for prefetching } else if strings.HasSuffix(f.fileName, ".db") { @@ -286,5 +289,5 @@ func handleRequest(w http.ResponseWriter, req *http.Request) error { } } - return err + return nil } diff --git a/urls_test.go b/urls_test.go index e4b4ab3..19a403f 100644 --- a/urls_test.go +++ b/urls_test.go @@ -44,12 +44,10 @@ func TestParseMirrorlist(t *testing.T) { tmpMirrorfile := path.Join(temp, "tmpMirrorFile") f, err := os.Create(tmpMirrorfile) - if err == nil { - f.Write([]byte(mirrorlist)) - f.Close() - f, err = os.Open(tmpMirrorfile) - } require.NoError(t, err) + f.Write([]byte(mirrorlist)) + f.Close() + f, err = os.Open(tmpMirrorfile) actualURLs, err := parseMirrorlistURLs(f) require.NoError(t, err)