From 78e45facd73337b60dcb4328f8b8c257520aaf8b Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Tue, 13 Aug 2013 23:18:17 -0400 Subject: [PATCH] Add file permission detection/restoring --- client/asink.go | 12 ++++++++++++ events.go | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/client/asink.go b/client/asink.go index 87a366c..78de1cf 100644 --- a/client/asink.go +++ b/client/asink.go @@ -113,6 +113,12 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) { panic(err) } + fileinfo, err := os.Stat(event.Path) + if err != nil && !util.ErrorFileNotFound(err) { + panic(err) + } + event.Permissions = fileinfo.Mode() + //get the file's hash hash, err := HashFile(tmpfilename) event.Hash = hash @@ -207,6 +213,12 @@ func ProcessRemoteEvent(globals AsinkGlobals, event *asink.Event) { panic(err) } } + if latestLocal == nil || event.Permissions != latestLocal.Permissions { + err := os.Chmod(event.Path, event.Permissions) + if err != nil && !util.ErrorFileNotFound(err) { + panic(err) + } + } } else { //intentionally ignore errors in case this file has been deleted out from under us os.Remove(event.Path) diff --git a/events.go b/events.go index c310d4a..7b37e83 100644 --- a/events.go +++ b/events.go @@ -1,5 +1,9 @@ package asink +import ( + "os" +) + //event type type EventType uint32 @@ -34,7 +38,7 @@ type Event struct { Hash string Predecessor string Timestamp int64 - Permissions uint32 + Permissions os.FileMode InDB bool `json:"-"` //defaults to false. Omitted from json marshalling. }