From 4c81d6967811d4327fe29885ea2b2f0e3c550c7a Mon Sep 17 00:00:00 2001 From: LEI Date: Wed, 12 Sep 2018 23:53:22 +0200 Subject: [PATCH] don --- internal/dot/copy.go | 33 ++++++++++++++++++++++----------- internal/pkg/pkg.go | 5 ++++- scripts/install.sh | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/internal/dot/copy.go b/internal/dot/copy.go index 6095c4a..9094663 100644 --- a/internal/dot/copy.go +++ b/internal/dot/copy.go @@ -153,6 +153,10 @@ func copyExists(src, dst string) (bool, error) { if err != nil { return false, err } + if rf.Length == -1 { + // Ignore failed HEAD request + return false, nil + } if !exists(dst) { // Stop here if the target does not exist return false, nil @@ -214,6 +218,7 @@ type remoteFile struct { Etag string } +// TODO: ask overwrite confirmation if remote file changed // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since func (r *remoteFile) Compare(name string) (bool, error) { f, err := os.Open(name) @@ -226,13 +231,15 @@ func (r *remoteFile) Compare(name string) (bool, error) { if err != nil { return false, err } - // TODO: ask overwrite confirmation + // if r.Length == -1 { + // return false, fmt.Errorf("%s: no content length", r.URL) + // } if fi.Size() != r.Length { - fmt.Println("DIFFERENT SIZE", fi.Size(), "->", r.Length) + // fmt.Println("DIFFERENT SIZE", fi.Size(), "->", r.Length) return false, nil } if fi.ModTime().After(r.Date) { - fmt.Println("DIFFERENT DATE", fi.ModTime(), "->", r.Date) + // fmt.Println("DIFFERENT DATE", fi.ModTime(), "->", r.Date) return false, nil } // fmt.Println("Etag", r.Etag) @@ -256,6 +263,7 @@ func newRemoteFile(url string) (*remoteFile, error) { }, } + //fmt.Println("> HEAD", r.URL) resp, err := client.Head(r.URL) if err != nil { return r, err @@ -275,18 +283,21 @@ func newRemoteFile(url string) (*remoteFile, error) { // return r, err // } // defer resp.Body.Close() - // body, err := ioutil.ReadAll(resp.Body) - // if err != nil { - // return r, err - // } - - if resp.StatusCode != 200 && resp.StatusCode != 302 { - fmt.Printf("HTTP %s: %+v\n%+v\n", resp.Status, url, resp) + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return r, err } + content := string(body) + if resp.StatusCode >= 400 { - return r, fmt.Errorf("%s: head request returned %+v", r.URL, resp.Status) + return r, fmt.Errorf("HEAD %s %s (%+v)", r.URL, resp.Status, content) + } else if resp.StatusCode != 200 && resp.StatusCode != 302 { + fmt.Fprintf(os.Stderr, "HEAD %s %s (%+v)\n", r.URL, resp.Status, content) } r.Length = resp.ContentLength + if resp.ContentLength == -1 && content != "" { + fmt.Fprintf(os.Stderr, "HEAD %s %s: no content length but got: %+v\n", r.URL, resp.Status, content) + } // // contentLen := resp.Header.Get("Content-Length") // if r.Length, err = strconv.ParseInt(contentLen, 10, 64); err != nil { // return r, err diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index 0e111ca..0e297d1 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -252,7 +252,10 @@ func Init(manager string) error { // }) // return err if !m.done && m.Init != nil { - return m.Init() + if err := m.Init(); err != nil { + return err + } + m.done = true } return nil } diff --git a/scripts/install.sh b/scripts/install.sh index 197208f..e324af0 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -120,7 +120,7 @@ initArch() { i386) ARCH="386" ;; ppc64) ARCH="ppc64" ;; ppc64le) ARCH="ppc64le" ;; - aarch64) ARCH="arm64" ;; + # aarch64) ARCH="arm64?" ;; # ?) ARCH="armv6" ;; *) echo >&2 "Architecture ${ARCH} is not supported by this installation script"