diff --git a/main.go b/main.go index cd8c08b..1782cc6 100644 --- a/main.go +++ b/main.go @@ -52,7 +52,7 @@ func init() { confIP := flag.String("ip", "", "this will overwrite Wide.IP if specified") confPort := flag.String("port", "", "this will overwrite Wide.Port if specified") confServer := flag.String("server", "", "this will overwrite Wide.Server if specified") - confLogLevel := flag.String("log_level", "debug", "this will overwrite Wide.LogLevel if specified") + confLogLevel := flag.String("log_level", "", "this will overwrite Wide.LogLevel if specified") confStaticServer := flag.String("static_server", "", "this will overwrite Wide.StaticServer if specified") confContext := flag.String("context", "", "this will overwrite Wide.Context if specified") confChannel := flag.String("channel", "", "this will overwrite Wide.Channel if specified") diff --git a/session/sessions.go b/session/sessions.go index 3edcb39..51224d2 100644 --- a/session/sessions.go +++ b/session/sessions.go @@ -333,32 +333,6 @@ func (sessions *wSessions) New(httpSession *sessions.Session, sid string) *WideS return ret } - go func() { - defer util.Recover() - - workspaces := filepath.SplitList(conf.GetUserWorkspace(username)) - for _, workspace := range workspaces { - filepath.Walk(filepath.Join(workspace, "src"), func(dirPath string, f os.FileInfo, err error) error { - if ".git" == f.Name() { // XXX: discard other unconcered dirs - return filepath.SkipDir - } - - if f.IsDir() { - if err = watcher.Add(dirPath); nil != err { - logger.Error(err, dirPath) - } - - logger.Tracef("Added a file watcher [%s]", dirPath) - } - - return nil - }) - - } - - ret.FileWatcher = watcher - }() - go func() { defer util.Recover() @@ -378,12 +352,18 @@ func (sessions *wSessions) New(httpSession *sessions.Session, sid string) *WideS return // release this gorutine } + logger.Info(event) + if event.Op&fsnotify.Create == fsnotify.Create { if err = watcher.Add(path); nil != err { logger.Warn(err, path) } - logger.Tracef("Added a file watcher [%s]", path) + if util.File.IsDir(path) { + break + } + + logger.Tracef("File watcher added a file [%s]", path) cmd := map[string]interface{}{"path": path, "dir": dir, "cmd": "create-file"} ch.WriteJSON(&cmd) @@ -403,6 +383,31 @@ func (sessions *wSessions) New(httpSession *sessions.Session, sid string) *WideS } }() + go func() { + defer util.Recover() + + workspaces := filepath.SplitList(conf.GetUserWorkspace(username)) + for _, workspace := range workspaces { + filepath.Walk(filepath.Join(workspace, "src"), func(dirPath string, f os.FileInfo, err error) error { + if ".git" == f.Name() { // XXX: discard other unconcered dirs + return filepath.SkipDir + } + + if f.IsDir() { + if err = watcher.Add(dirPath); nil != err { + logger.Error(err, dirPath) + } + + logger.Tracef("File watcher added a dir [%s]", dirPath) + } + + return nil + }) + } + + ret.FileWatcher = watcher + }() + return ret }