Add file permission detection/restoring
This commit is contained in:
parent
fae1ed38d5
commit
78e45facd7
@ -113,6 +113,12 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
|
|||||||
panic(err)
|
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
|
//get the file's hash
|
||||||
hash, err := HashFile(tmpfilename)
|
hash, err := HashFile(tmpfilename)
|
||||||
event.Hash = hash
|
event.Hash = hash
|
||||||
@ -207,6 +213,12 @@ func ProcessRemoteEvent(globals AsinkGlobals, event *asink.Event) {
|
|||||||
panic(err)
|
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 {
|
} else {
|
||||||
//intentionally ignore errors in case this file has been deleted out from under us
|
//intentionally ignore errors in case this file has been deleted out from under us
|
||||||
os.Remove(event.Path)
|
os.Remove(event.Path)
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package asink
|
package asink
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
//event type
|
//event type
|
||||||
type EventType uint32
|
type EventType uint32
|
||||||
|
|
||||||
@ -34,7 +38,7 @@ type Event struct {
|
|||||||
Hash string
|
Hash string
|
||||||
Predecessor string
|
Predecessor string
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
Permissions uint32
|
Permissions os.FileMode
|
||||||
InDB bool `json:"-"` //defaults to false. Omitted from json marshalling.
|
InDB bool `json:"-"` //defaults to false. Omitted from json marshalling.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user