From 3120edd0a7acca5bbf35340d7ccb4c4ffb836f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 14 Jun 2015 14:59:07 +0200 Subject: [PATCH] Simplify HTTP not modified replies --- cmd/fdroidcl/http.go | 11 +++++------ cmd/fdroidcl/main.go | 8 ++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/cmd/fdroidcl/http.go b/cmd/fdroidcl/http.go index 1236bf0..b92b141 100644 --- a/cmd/fdroidcl/http.go +++ b/cmd/fdroidcl/http.go @@ -4,16 +4,13 @@ package main import ( - "errors" + "fmt" "io" "io/ioutil" - "log" "net/http" "os" ) -var errNotModified = errors.New("etag matches, file was not modified") - func respEtag(resp *http.Response) string { etags, e := resp.Header["Etag"] if !e || len(etags) == 0 { @@ -23,7 +20,7 @@ func respEtag(resp *http.Response) string { } func downloadEtag(url, path string) error { - log.Printf("Downloading %s", url) + fmt.Printf("Downloading %s...", url) client := &http.Client{} req, err := http.NewRequest("GET", url, nil) @@ -39,7 +36,8 @@ func downloadEtag(url, path string) error { } defer resp.Body.Close() if resp.StatusCode == http.StatusNotModified { - return errNotModified + fmt.Println(" not modified") + return nil } f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { @@ -53,5 +51,6 @@ func downloadEtag(url, path string) error { if err2 != nil { return err2 } + fmt.Println(" done") return nil } diff --git a/cmd/fdroidcl/main.go b/cmd/fdroidcl/main.go index db74de1..27dd844 100644 --- a/cmd/fdroidcl/main.go +++ b/cmd/fdroidcl/main.go @@ -179,9 +179,8 @@ func indexPath(name string) string { } func updateIndex() error { - p := indexPath(repoName) url := fmt.Sprintf("%s/%s", repoURL, "index.jar") - if err := downloadEtag(url, p); err != nil { + if err := downloadEtag(url, indexPath(repoName)); err != nil { return err } return nil @@ -252,10 +251,7 @@ func main() { switch cmd { case "update": - err := updateIndex() - if err == errNotModified { - log.Print("Index up to date") - } else if err != nil { + if err := updateIndex(); err != nil { log.Fatalf("Could not update index: %v", err) } case "list":