upload: check remote before uploading
This commit is contained in:
parent
8e7da00c42
commit
5a5d133e9a
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user