Make watcher scan all directories for client, start adding user
management to server with socket communication via admin binary
This commit is contained in:
@ -121,7 +121,7 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
|
||||
if err != nil {
|
||||
//bail out if the file we are trying to upload already got deleted
|
||||
if util.ErrorFileNotFound(err) {
|
||||
event.Status |= asink.DISCARDED
|
||||
event.LocalStatus |= asink.DISCARDED
|
||||
return
|
||||
}
|
||||
panic(err)
|
||||
@ -132,7 +132,7 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
|
||||
if err != nil {
|
||||
//bail out if the file we are trying to upload already got deleted
|
||||
if util.ErrorFileNotFound(err) {
|
||||
event.Status |= asink.DISCARDED
|
||||
event.LocalStatus |= asink.DISCARDED
|
||||
return
|
||||
}
|
||||
panic(err)
|
||||
@ -150,7 +150,7 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
|
||||
//If the file didn't actually change, squash this event
|
||||
if latestLocal != nil && event.Hash == latestLocal.Hash {
|
||||
os.Remove(tmpfilename)
|
||||
event.Status |= asink.DISCARDED
|
||||
event.LocalStatus |= asink.DISCARDED
|
||||
return
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ func ProcessLocalEvent(globals AsinkGlobals, event *asink.Event) {
|
||||
} else {
|
||||
//if we're trying to delete a file that we thought was already deleted, there's no need to delete it again
|
||||
if latestLocal != nil && latestLocal.IsDelete() {
|
||||
event.Status |= asink.DISCARDED
|
||||
event.LocalStatus |= asink.DISCARDED
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -195,13 +195,15 @@ func ProcessRemoteEvent(globals AsinkGlobals, event *asink.Event) {
|
||||
//if we already have this event, or if it is older than our most recent event, bail out
|
||||
if latestLocal != nil {
|
||||
if event.Timestamp < latestLocal.Timestamp || event.IsSameEvent(latestLocal) {
|
||||
event.Status |= asink.DISCARDED
|
||||
event.LocalStatus |= asink.DISCARDED
|
||||
return
|
||||
}
|
||||
|
||||
if latestLocal.Hash != event.Predecessor && latestLocal.Hash != event.Hash {
|
||||
panic("conflict")
|
||||
//TODO handle conflict
|
||||
fmt.Printf("conflict:\n")
|
||||
fmt.Printf("OLD %+v\n", latestLocal)
|
||||
fmt.Printf("NEW %+v\n", event)
|
||||
//TODO handle conflict?
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ func GetAndInitDB(config *conf.ConfigFile) (*AsinkDB, error) {
|
||||
}
|
||||
if !rows.Next() {
|
||||
//if this is false, it means no rows were returned
|
||||
tx.Exec("CREATE TABLE events (id INTEGER, localid INTEGER PRIMARY KEY ASC, type INTEGER, status INTEGER, path TEXT, hash TEXT, predecessor TEXT, timestamp INTEGER, permissions INTEGER);")
|
||||
tx.Exec("CREATE TABLE events (id INTEGER, localid INTEGER PRIMARY KEY ASC, type INTEGER, localstatus INTEGER, path TEXT, hash TEXT, predecessor TEXT, timestamp INTEGER, permissions INTEGER);")
|
||||
// tx.Exec("CREATE INDEX IF NOT EXISTS localididx on events (localid)")
|
||||
tx.Exec("CREATE INDEX IF NOT EXISTS ididx on events (id);")
|
||||
tx.Exec("CREATE INDEX IF NOT EXISTS pathidx on events (path);")
|
||||
@ -66,7 +66,7 @@ func (adb *AsinkDB) DatabaseAddEvent(e *asink.Event) (err error) {
|
||||
adb.lock.Unlock()
|
||||
}()
|
||||
|
||||
result, err := tx.Exec("INSERT INTO events (id, type, status, path, hash, predecessor, timestamp, permissions) VALUES (?,?,?,?,?,?,?,?);", e.Id, e.Type, e.Status, e.Path, e.Hash, e.Predecessor, e.Timestamp, e.Permissions)
|
||||
result, err := tx.Exec("INSERT INTO events (id, type, localstatus, path, hash, predecessor, timestamp, permissions) VALUES (?,?,?,?,?,?,?,?);", e.Id, e.Type, e.LocalStatus, e.Path, e.Hash, e.Predecessor, e.Timestamp, e.Permissions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -102,7 +102,7 @@ func (adb *AsinkDB) DatabaseUpdateEvent(e *asink.Event) (err error) {
|
||||
adb.lock.Unlock()
|
||||
}()
|
||||
|
||||
result, err := tx.Exec("UPDATE events SET id=?, type=?, status=?, path=?, hash=?, prececessor=?, timestamp=?, permissions=? WHERE localid=?;", e.Id, e.Type, e.Status, e.Path, e.Hash, e.Predecessor, e.Timestamp, e.Permissions, e.LocalId)
|
||||
result, err := tx.Exec("UPDATE events SET id=?, type=?, localstatus=?, path=?, hash=?, prececessor=?, timestamp=?, permissions=? WHERE localid=?;", e.Id, e.Type, e.LocalStatus, e.Path, e.Hash, e.Predecessor, e.Timestamp, e.Permissions, e.LocalId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -127,10 +127,10 @@ func (adb *AsinkDB) DatabaseLatestEventForPath(path string) (event *asink.Event,
|
||||
//make sure the database gets unlocked
|
||||
defer adb.lock.Unlock()
|
||||
|
||||
row := adb.db.QueryRow("SELECT id, localid, type, status, path, hash, predecessor, timestamp, permissions FROM events WHERE path == ? ORDER BY timestamp DESC LIMIT 1;", path)
|
||||
row := adb.db.QueryRow("SELECT id, localid, type, localstatus, path, hash, predecessor, timestamp, permissions FROM events WHERE path == ? ORDER BY timestamp DESC LIMIT 1;", path)
|
||||
|
||||
event = new(asink.Event)
|
||||
err = row.Scan(&event.Id, &event.LocalId, &event.Type, &event.Status, &event.Path, &event.Hash, &event.Predecessor, &event.Timestamp, &event.Permissions)
|
||||
err = row.Scan(&event.Id, &event.LocalId, &event.Type, &event.LocalStatus, &event.Path, &event.Hash, &event.Predecessor, &event.Timestamp, &event.Permissions)
|
||||
|
||||
switch {
|
||||
case err == sql.ErrNoRows:
|
||||
@ -148,10 +148,10 @@ func (adb *AsinkDB) DatabaseLatestRemoteEvent() (event *asink.Event, err error)
|
||||
//make sure the database gets unlocked
|
||||
defer adb.lock.Unlock()
|
||||
|
||||
row := adb.db.QueryRow("SELECT id, localid, type, status, path, hash, predecessor, timestamp, permissions FROM events WHERE id > 0 ORDER BY id DESC LIMIT 1;")
|
||||
row := adb.db.QueryRow("SELECT id, localid, type, localstatus, path, hash, predecessor, timestamp, permissions FROM events WHERE id > 0 ORDER BY id DESC LIMIT 1;")
|
||||
|
||||
event = new(asink.Event)
|
||||
err = row.Scan(&event.Id, &event.LocalId, &event.Type, &event.Status, &event.Path, &event.Hash, &event.Predecessor, &event.Timestamp, &event.Permissions)
|
||||
err = row.Scan(&event.Id, &event.LocalId, &event.Type, &event.LocalStatus, &event.Path, &event.Hash, &event.Predecessor, &event.Timestamp, &event.Permissions)
|
||||
|
||||
switch {
|
||||
case err == sql.ErrNoRows:
|
||||
|
@ -33,7 +33,7 @@ func PathLocker(db *AsinkDB) {
|
||||
case event = <-pathUnlockerChan:
|
||||
if v, ok = m[event.Path]; ok != false {
|
||||
//only update status in data structures if the event hasn't been discarded
|
||||
if event.Status&asink.DISCARDED == 0 {
|
||||
if event.LocalStatus&asink.DISCARDED == 0 {
|
||||
if v.latestEvent == nil || !v.latestEvent.IsSameEvent(event) {
|
||||
err := db.DatabaseAddEvent(event)
|
||||
if err != nil {
|
||||
|
@ -21,6 +21,12 @@ func StartWatching(watchDir string, fileUpdates chan *asink.Event) {
|
||||
if err != nil {
|
||||
panic("Failed to watch " + path)
|
||||
}
|
||||
} else if info.Mode().IsRegular() {
|
||||
event := new(asink.Event)
|
||||
event.Path = path
|
||||
event.Type = asink.UPDATE
|
||||
event.Timestamp = info.ModTime().UnixNano()
|
||||
fileUpdates <- event
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user