From efcceccac4b25aebcb0af83748fcedc1e810defc Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 16 May 2019 10:52:31 +0800 Subject: [PATCH] :art: Cleanup code --- conf/wide.go | 17 +++++++++++------ session/sessions.go | 12 ++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/conf/wide.go b/conf/wide.go index afdb0e1..3e35d2e 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -83,14 +83,19 @@ var Wide *conf // configurations of users. var Users []*User -// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json. -func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, - confPlayground string, confUsersWorkspaces string) { - // XXX: ugly args list.... +// Indicates whether Docker is available. +var Docker bool - initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, - confPlayground, confUsersWorkspaces) +// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json. +func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground string, confUsersWorkspaces string) { + initWide(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel, confPlayground, confUsersWorkspaces) initUsers() + + cmd := exec.Command("docker", "version") + _, err := cmd.CombinedOutput() + if nil != err { + logger.Warn("Not found 'docker' installed, running user's code will cause security problem") + } } func initUsers() { diff --git a/session/sessions.go b/session/sessions.go index 268bee0..a83f5f5 100644 --- a/session/sessions.go +++ b/session/sessions.go @@ -480,7 +480,7 @@ func (sessions *wSessions) new(httpSession *sessions.Session, sid string) *WideS for { ch := SessionWS[sid] if nil == ch { - return // release this gorutine + return // release this goroutine } select { @@ -506,17 +506,13 @@ func (sessions *wSessions) new(httpSession *sessions.Session, sid string) *WideS } } - cmd := map[string]interface{}{"path": path, "dir": dir, - "cmd": "create-file", "type": fileType} + cmd := map[string]interface{}{"path": path, "dir": dir, "cmd": "create-file", "type": fileType} ch.WriteJSON(&cmd) } else if event.Op&fsnotify.Remove == fsnotify.Remove { - cmd := map[string]interface{}{"path": path, "dir": dir, - "cmd": "remove-file", "type": ""} + cmd := map[string]interface{}{"path": path, "dir": dir, "cmd": "remove-file", "type": ""} ch.WriteJSON(&cmd) - } else if event.Op&fsnotify.Rename == fsnotify.Rename { - cmd := map[string]interface{}{"path": path, "dir": dir, - "cmd": "rename-file", "type": ""} + cmd := map[string]interface{}{"path": path, "dir": dir, "cmd": "rename-file", "type": ""} ch.WriteJSON(&cmd) } case err := <-watcher.Errors: