add ErrorFileNotFound util function
This commit is contained in:
parent
bdd8032f29
commit
f3b4294b23
@ -10,7 +10,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AsinkGlobals struct {
|
type AsinkGlobals struct {
|
||||||
@ -110,14 +109,9 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
|
|||||||
//copy to tmp
|
//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
|
//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 && !util.ErrorFileNotFound(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)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
event.Status |= asink.COPIED_TO_TMP
|
event.Status |= asink.COPIED_TO_TMP
|
||||||
|
|
||||||
//get the file's hash
|
//get the file's hash
|
||||||
|
@ -15,7 +15,7 @@ type AsinkDB struct {
|
|||||||
func GetAndInitDB() (*AsinkDB, error) {
|
func GetAndInitDB() (*AsinkDB, error) {
|
||||||
dbLocation := "asink-server.db" //TODO make me configurable
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EnsureDirExists(dir string) error {
|
func EnsureDirExists(dir string) error {
|
||||||
@ -42,3 +43,10 @@ func CopyToTmp(src string, tmpdir string) (string, error) {
|
|||||||
|
|
||||||
return outfile.Name(), nil
|
return outfile.Name(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ErrorFileNotFound(err error) bool {
|
||||||
|
if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user