This commit is contained in:
Liang Ding 2015-09-26 18:07:55 +08:00
parent 38c742b405
commit 915f7e3cee
2 changed files with 33 additions and 28 deletions

View File

@ -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")

View File

@ -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
}