Skip to content

Commit

Permalink
Check errors right after the function call
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol committed Nov 17, 2023
1 parent c28edcf commit e885028
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 8 additions & 5 deletions pacoloco.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,22 @@ 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") {
updateDBRequestedDB(f.repoName, f.pathAtRepo, f.fileName)
}
}

return err
return nil
}

func handleRequest(w http.ResponseWriter, req *http.Request) error {
Expand Down Expand Up @@ -278,13 +281,13 @@ 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") {
updateDBRequestedDB(f.repoName, f.pathAtRepo, f.fileName)
}
}

return err
return nil
}
8 changes: 3 additions & 5 deletions urls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e885028

Please sign in to comment.