From 5a5d133e9adb17c997f96947af851aa1bf995e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Fri, 18 Oct 2019 11:41:16 +1100 Subject: [PATCH] upload: check remote before uploading --- cmd/dkl-store-upload/main.go | 14 ++++++++++++++ modd.conf | 4 ++++ 2 files changed, 18 insertions(+) create mode 100644 modd.conf diff --git a/cmd/dkl-store-upload/main.go b/cmd/dkl-store-upload/main.go index fd04351..f6ddf6c 100644 --- a/cmd/dkl-store-upload/main.go +++ b/cmd/dkl-store-upload/main.go @@ -30,6 +30,8 @@ func main() { in, err := os.Open(inPath) fail(err) + defer in.Close() + // hash the file log.Print("hashing...") h := sha1.New() @@ -40,6 +42,18 @@ func main() { log.Print("SHA1 of source: ", sha1Hex) + // check remote + head, err := http.Head(outURL) + fail(err) + + if head.StatusCode == 200 { + remoteSHA1 := head.Header.Get("X-Content-SHA1") + if sha1Hex == remoteSHA1 { + log.Print("remote is already up-to-date") + return + } + } + // rewind _, err = in.Seek(0, os.SEEK_SET) fail(err) diff --git a/modd.conf b/modd.conf new file mode 100644 index 0000000..9996a60 --- /dev/null +++ b/modd.conf @@ -0,0 +1,4 @@ +**/*.go go.* { + prep: go test ./... + prep: go install ./cmd/... +}