aboutsummaryrefslogtreecommitdiffstats
path: root/compare.go
diff options
context:
space:
mode:
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))
+}