From 1254a7fb45dd99bf9db74e8a765cb5f092b3e57e Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Sun, 8 Sep 2013 23:30:13 -0400 Subject: [PATCH] Still send event when files' permissions change --- asink/client.go | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/asink/client.go b/asink/client.go index 9854acc..d241841 100644 --- a/asink/client.go +++ b/asink/client.go @@ -182,30 +182,33 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) { } event.Hash = hash - //If the file didn't actually change, squash this event + //If the hash is the same, don't try to upload the event again if latestLocal != nil && event.Hash == latestLocal.Hash { os.Remove(tmpfilename) - event.LocalStatus |= asink.DISCARDED - return - } + //If neither the file contents nor permissions changed, squash this event completely + if event.Permissions == latestLocal.Permissions { + event.LocalStatus |= asink.DISCARDED + return + } + } else { + //rename to local cache w/ filename=hash + cachedFilename := path.Join(globals.cacheDir, event.Hash) + err = os.Rename(tmpfilename, cachedFilename) + if err != nil { + err := os.Remove(tmpfilename) + if err != nil { + panic(err) + } + panic(err) + } - //rename to local cache w/ filename=hash - cachedFilename := path.Join(globals.cacheDir, event.Hash) - err = os.Rename(tmpfilename, cachedFilename) - if err != nil { - err := os.Remove(tmpfilename) + //upload file to remote storage + StatStartUpload() + err = globals.storage.Put(cachedFilename, event.Hash) + StatStopUpload() if err != nil { panic(err) } - panic(err) - } - - //upload file to remote storage - StatStartUpload() - err = globals.storage.Put(cachedFilename, event.Hash) - StatStopUpload() - if err != nil { - panic(err) } } else { //if we're trying to delete a file that we thought was already deleted, there's no need to delete it again @@ -307,7 +310,7 @@ func ProcessRemoteEvent(globals AsinkGlobals, event *asink.Event) { panic(err) } } - if latestLocal == nil || event.Permissions != latestLocal.Permissions { + if latestLocal == nil || event.Hash != latestLocal.Hash || event.Permissions != latestLocal.Permissions { err := os.Chmod(absolutePath, event.Permissions) if err != nil && !util.ErrorFileNotFound(err) { panic(err)