From f3b4294b238fc9795215bdb76abf96a03ed7b539 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Tue, 13 Aug 2013 23:12:08 -0400 Subject: [PATCH] add ErrorFileNotFound util function --- client/asink.go | 10 ++-------- server/database.go | 2 +- util/util.go | 8 ++++++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/asink.go b/client/asink.go index 076432b..f3df735 100644 --- a/client/asink.go +++ b/client/asink.go @@ -10,7 +10,6 @@ import ( "os" "os/user" "path" - "syscall" ) type AsinkGlobals struct { @@ -110,13 +109,8 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) { //copy to tmp //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) - if err != nil { - 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) - } + if err != nil && !util.ErrorFileNotFound(err) { + panic(err) } event.Status |= asink.COPIED_TO_TMP diff --git a/server/database.go b/server/database.go index c30b479..2a842de 100644 --- a/server/database.go +++ b/server/database.go @@ -15,7 +15,7 @@ type AsinkDB struct { func GetAndInitDB() (*AsinkDB, error) { dbLocation := "asink-server.db" //TODO make me configurable - db, err := sql.Open("sqlite3", dbLocation) + db, err := sql.Open("sqlite3", "file:"+dbLocation+"?cache=shared&mode=rwc") if err != nil { return nil, err } diff --git a/util/util.go b/util/util.go index 0316361..c2d35b9 100644 --- a/util/util.go +++ b/util/util.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "path" + "syscall" ) func EnsureDirExists(dir string) error { @@ -42,3 +43,10 @@ func CopyToTmp(src string, tmpdir string) (string, error) { return outfile.Name(), nil } + +func ErrorFileNotFound(err error) bool { + if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT { + return true + } + return false +}