diff --git a/cmd/fdroidcl/download.go b/cmd/fdroidcl/download.go index 91dbf6e..3fcae3b 100644 --- a/cmd/fdroidcl/download.go +++ b/cmd/fdroidcl/download.go @@ -39,7 +39,8 @@ func runDownload(args []string) { func downloadApk(apk *fdroidcl.Apk) string { url := apk.URL() path := apkPath(apk.ApkName) - if err := downloadEtag(url, path, apk.Hash.Data); err != nil { + if err := downloadEtag(url, path, apk.Hash.Data); err == errNotModified { + } else if err != nil { log.Fatalf("Could not download %s: %v", apk.AppID, err) } return path diff --git a/cmd/fdroidcl/update.go b/cmd/fdroidcl/update.go index bfab95d..517c6c4 100644 --- a/cmd/fdroidcl/update.go +++ b/cmd/fdroidcl/update.go @@ -29,14 +29,22 @@ func init() { } func runUpdate(args []string) { + anyModified := false for _, r := range config.Repos { if !r.Enabled { continue } - if err := r.updateIndex(); err != nil { + if err := r.updateIndex(); err == errNotModified { + } else if err != nil { log.Fatalf("Could not update index: %v", err) + } else { + anyModified = true } } + if anyModified { + cache := filepath.Join(mustData(), "cache-gob") + os.Remove(cache) + } } const jarFile = "index.jar" @@ -71,10 +79,11 @@ func respEtag(resp *http.Response) string { return etags[0] } +var errNotModified = fmt.Errorf("not modified") + func downloadEtag(url, path string, sum []byte) error { fmt.Printf("Downloading %s... ", url) defer fmt.Println() - client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { return err @@ -86,6 +95,7 @@ func downloadEtag(url, path string, sum []byte) error { req.Header.Add("If-None-Match", string(etag)) } + client := &http.Client{} resp, err := client.Do(req) if err != nil { return err @@ -97,7 +107,7 @@ func downloadEtag(url, path string, sum []byte) error { } if resp.StatusCode == http.StatusNotModified { fmt.Printf("not modified") - return nil + return errNotModified } f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) if err != nil {