Miscellaneous bug fixes
This commit is contained in:
parent
2569f4cfbf
commit
bdd8032f29
@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AsinkGlobals struct {
|
type AsinkGlobals struct {
|
||||||
@ -110,7 +111,12 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
|
|||||||
//TODO upload in chunks and check modification times to make sure it hasn't been changed instead of copying the whole thing off
|
//TODO upload in chunks and check modification times to make sure it hasn't been changed instead of copying the whole thing off
|
||||||
tmpfilename, err := util.CopyToTmp(event.Path, globals.tmpDir)
|
tmpfilename, err := util.CopyToTmp(event.Path, globals.tmpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {
|
||||||
|
//if the file doesn't exist, it must've been deleted out from under us, disregard this event
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event.Status |= asink.COPIED_TO_TMP
|
event.Status |= asink.COPIED_TO_TMP
|
||||||
|
|
||||||
@ -122,6 +128,12 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
|
|||||||
}
|
}
|
||||||
event.Status |= asink.HASHED
|
event.Status |= asink.HASHED
|
||||||
|
|
||||||
|
//If the file didn't actually change, squash this event
|
||||||
|
if latestLocal != nil && event.Hash == latestLocal.Hash {
|
||||||
|
os.Remove(tmpfilename)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//rename to local cache w/ filename=hash
|
//rename to local cache w/ filename=hash
|
||||||
err = os.Rename(tmpfilename, path.Join(globals.cacheDir, event.Hash))
|
err = os.Rename(tmpfilename, path.Join(globals.cacheDir, event.Hash))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -188,6 +200,10 @@ func ProcessRemoteEvent(globals AsinkGlobals, event *asink.Event) {
|
|||||||
}
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
//intentionally ignore errors in case this file has been deleted out from under us
|
||||||
|
os.Remove(event.Path)
|
||||||
|
//TODO delete file hierarchy beneath this file if its the last one in its directory?
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(event)
|
fmt.Println(event)
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func HashFile(filename string) (string, error) {
|
func HashFile(filename string) (string, error) {
|
||||||
|
//TODO change to sha512?
|
||||||
hashfn := sha256.New()
|
hashfn := sha256.New()
|
||||||
|
|
||||||
infile, err := os.Open(filename)
|
infile, err := os.Open(filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user