upload: check remote before uploading

This commit is contained in:
Mikaël Cluseau 2019-10-18 11:41:16 +11:00
parent 8e7da00c42
commit 5a5d133e9a
2 changed files with 18 additions and 0 deletions

View File

@ -30,6 +30,8 @@ func main() {
in, err := os.Open(inPath) in, err := os.Open(inPath)
fail(err) fail(err)
defer in.Close()
// hash the file // hash the file
log.Print("hashing...") log.Print("hashing...")
h := sha1.New() h := sha1.New()
@ -40,6 +42,18 @@ func main() {
log.Print("SHA1 of source: ", sha1Hex) 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 // rewind
_, err = in.Seek(0, os.SEEK_SET) _, err = in.Seek(0, os.SEEK_SET)
fail(err) fail(err)

4
modd.conf Normal file
View File

@ -0,0 +1,4 @@
**/*.go go.* {
prep: go test ./...
prep: go install ./cmd/...
}