aboutsummaryrefslogtreecommitdiffstats
path: root/compare.go
diff options
context:
space:
mode:
authorPetter Rasmussen2016-02-06 13:08:33 +0100
committerPetter Rasmussen2016-02-06 13:08:33 +0100
commitce32c7536cf40afae065b09018c05da6ba221c55 (patch)
treee08b55be1974ba9c05df59d2a8cb10fb64d42dfe /compare.go
parent77d8e36d48c73fe1d0dc86b6736c32e5fd1f744a (diff)
downloadgdrive-ce32c7536cf40afae065b09018c05da6ba221c55.tar.bz2
Give FileComparer as argument
Diffstat (limited to 'compare.go')
-rw-r--r--compare.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/compare.go b/compare.go
new file mode 100644
index 0000000..7275a38
--- /dev/null
+++ b/compare.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "io"
+ "crypto/md5"
+ "./drive"
+)
+
+type Md5Comparer struct {}
+
+func (self Md5Comparer) Changed(local *drive.LocalFile, remote *drive.RemoteFile) bool {
+ return remote.Md5() != md5sum(local.AbsPath())
+}
+
+func md5sum(path string) string {
+ h := md5.New()
+ f, err := os.Open(path)
+ if err != nil {
+ return ""
+ }
+ defer f.Close()
+
+ io.Copy(h, f)
+ return fmt.Sprintf("%x", h.Sum(nil))
+}