Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
elgs committed Aug 14, 2017
1 parent 899b91a commit 218192c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Server
Installation
---
`go get github.com/elgs/filesync/gsyncd`
`go get github.com/elgs/filesync/gsync`
Run
---
`gsyncd gsyncd.json`
Expand Down
8 changes: 0 additions & 8 deletions gsync/gsync.json

This file was deleted.

4 changes: 2 additions & 2 deletions gsyncd/gsyncd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"database/sql"
"fmt"
simplejson "github.com/bitly/go-simplejson"
"github.com/howeyc/fsnotify"
_ "github.com/mattn/go-sqlite3"
"github.com/elgs/filesync/api"
"github.com/elgs/filesync/index"
"github.com/fsnotify/fsnotify"
_ "github.com/mattn/go-sqlite3"
"io/ioutil"
"os"
"runtime"
Expand Down
8 changes: 0 additions & 8 deletions gsyncd/gsyncd.json

This file was deleted.

16 changes: 8 additions & 8 deletions index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package index
import (
"database/sql"
"fmt"
"github.com/howeyc/fsnotify"
"github.com/fsnotify/fsnotify"
"hash/crc32"
"math"
"os"
Expand Down Expand Up @@ -254,7 +254,7 @@ func WatchRecursively(watcher *fsnotify.Watcher, root string, monitored string)
return nil
}

watcher.Watch(thePath[0 : len(thePath)-1])
watcher.Add(thePath[0: len(thePath)-1])
// update index
if v, ok := mapFiles[thePath[len(monitored):]]; !ok {
psInsertFiles.Exec(thePath[len(monitored):], info.ModTime().Unix(), -1, uint32(info.Mode().Perm()), "ready", time.Now().Unix())
Expand Down Expand Up @@ -349,31 +349,31 @@ func exists(path string) bool {
func ProcessEvent(watcher *fsnotify.Watcher, monitored string) {
for {
select {
case ev := <-watcher.Event:
case ev := <-watcher.Events:
//fmt.Println("event:", ev, ":", monitored)
info, _ := os.Lstat(ev.Name)
if info == nil {
ProcessFileDelete(ev.Name, monitored)
} else if ev.IsCreate() {
} else if ev.Op&fsnotify.Create == fsnotify.Create {
if info.IsDir() {
WatchRecursively(watcher, ev.Name, monitored)
//fmt.Println("Created dir: " + ev.Name)
} else {
ProcessFileChange(ev.Name, info, monitored)
//fmt.Println("Created file: " + ev.Name)
}
} else if ev.IsModify() {
} else if ev.Op&fsnotify.Write == fsnotify.Write {
if info.IsDir() {
ProcessDirChange(ev.Name, info, monitored)
//fmt.Println("Modified dir: " + ev.Name)
} else {
ProcessFileChange(ev.Name, info, monitored)
//fmt.Println("Modified file: " + ev.Name)
}
} else if ev.IsDelete() {
} else if ev.Op&fsnotify.Remove == fsnotify.Remove {
ProcessFileDelete(ev.Name, monitored)
//fmt.Println("Deleted: " + ev.Name)
} else if ev.IsRename() {
} else if ev.Op&fsnotify.Rename == fsnotify.Rename {
if exists(ev.Name) {
if info.IsDir() {
WatchRecursively(watcher, ev.Name, monitored)
Expand All @@ -386,7 +386,7 @@ func ProcessEvent(watcher *fsnotify.Watcher, monitored string) {
ProcessFileDelete(ev.Name, monitored)
}
}
case err := <-watcher.Error:
case err := <-watcher.Errors:
fmt.Println("error:", err)
case <-time.After(time.Minute):
//fmt.Println("I'm idle, so I decided to do a patrol")
Expand Down

0 comments on commit 218192c

Please sign in to comment.