From 932d472c0d9c86a4fcaf1073debfa2604eebbe46 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 5 Sep 2014 11:07:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/wide.go | 8 ++++---- conf/wide.json | 4 ++-- editor/editors.go | 9 +++------ file/files.go | 3 +-- output/outputs.go | 3 +-- shell/shells.go | 4 ++-- user/users.go | 6 +++--- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/conf/wide.go b/conf/wide.go index 5772be5..64d5ecf 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -28,8 +28,8 @@ type conf struct { StaticPath string MaxProcs int RuntimeMode string - Repos string - UserRepos string + Workspace string + UserWorkspaces string Users []User } @@ -91,8 +91,8 @@ func Load() { pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))] glog.Infof("pwd [%s]", pwd) - Wide.Repos = strings.Replace(Wide.Repos, "{pwd}", pwd, 1) - Wide.UserRepos = strings.Replace(Wide.UserRepos, "{pwd}", pwd, 1) + Wide.Workspace = strings.Replace(Wide.Workspace, "{pwd}", pwd, 1) + Wide.UserWorkspaces = strings.Replace(Wide.UserWorkspaces, "{pwd}", pwd, 1) glog.Info("Conf: \n" + string(bytes)) } diff --git a/conf/wide.json b/conf/wide.json index 71c6ff3..931e5fd 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -9,8 +9,8 @@ "StaticPath": "", "MaxProcs": 4, "RuntimeMode": "dev", - "Repos": "{pwd}/data/workspace/src", - "UserRepos": "{pwd}/data/user_workspaces/{user}/src", + "Workspace": "{pwd}/data/workspace", + "UserWorkspaces": "{pwd}/data/user_workspaces", "Users": [ { "Name": "admin", diff --git a/editor/editors.go b/editor/editors.go index 9a252b2..d72f28b 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -11,7 +11,6 @@ import ( "net/http" "os" "os/exec" - "path/filepath" "runtime" "strconv" "strings" @@ -151,15 +150,13 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { // glog.Infof("offset: %d", offset) - userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1) - userWorkspace := userRepos[:strings.LastIndex(userRepos, "/src")] - userWorkspace = filepath.FromSlash(userWorkspace) + userWorkspace := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username + //glog.Infof("User [%s] workspace [%s]", username, userWorkspace) userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) + runtime.GOOS + "_" + runtime.GOARCH - masterWorkspace := conf.Wide.Repos[:strings.LastIndex(conf.Wide.Repos, "/src")] - masterWorkspace = filepath.FromSlash(masterWorkspace) + masterWorkspace := conf.Wide.Workspace //glog.Infof("Master workspace [%s]", masterWorkspace) masterLib := masterWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) + runtime.GOOS + "_" + runtime.GOARCH diff --git a/file/files.go b/file/files.go index 9b56fc0..75a3839 100644 --- a/file/files.go +++ b/file/files.go @@ -21,8 +21,7 @@ func GetFiles(w http.ResponseWriter, r *http.Request) { session, _ := user.Session.Get(r, "wide-session") username := session.Values["username"].(string) - - userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1) + userRepos := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username + string(os.PathSeparator) + "src" root := FileNode{"projects", userRepos, "d", []*FileNode{}} fileInfo, _ := os.Lstat(userRepos) diff --git a/output/outputs.go b/output/outputs.go index 1338466..f73697b 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -231,8 +231,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { } func setCmdEnv(cmd *exec.Cmd, username string) { - userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1) - userWorkspace := userRepos[:strings.LastIndex(userRepos, "/src")] + userWorkspace := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username cmd.Env = append(cmd.Env, "GOPATH="+userWorkspace, diff --git a/shell/shells.go b/shell/shells.go index 3ef9fa5..9796a31 100644 --- a/shell/shells.go +++ b/shell/shells.go @@ -97,8 +97,8 @@ func pipeCommands(commands ...*exec.Cmd) string { func setCmdEnv(cmd *exec.Cmd) { // TODO: 使用用户自己的仓库路径设置 GOPATH - cmd.Env = append(cmd.Env, "TERM=xterm", "GOPATH="+conf.Wide.Repos, + cmd.Env = append(cmd.Env, "TERM=xterm", "GOPATH="+conf.Wide.Workspace, "GOROOT="+os.Getenv("GOROOT")) - cmd.Dir = conf.Wide.Repos + cmd.Dir = conf.Wide.Workspace } diff --git a/user/users.go b/user/users.go index 065675e..8acbdae 100644 --- a/user/users.go +++ b/user/users.go @@ -6,7 +6,7 @@ import ( "github.com/b3log/wide/util" "github.com/golang/glog" "net/http" - "strings" + "os" ) const ( @@ -47,11 +47,11 @@ func InitGitRepos(w http.ResponseWriter, r *http.Request) { session, _ := Session.Get(r, "wide-session") username := session.Values["username"].(string) - userRepos := strings.Replace(conf.Wide.UserRepos, "{user}", username, -1) + userRepos := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username + string(os.PathSeparator) + "src" // TODO: git clone - glog.Infof("Git Cloned from [%s] to [%s]", conf.Wide.Repos, userRepos) + glog.Infof("Git Cloned from [%s] to [%s]", conf.Wide.Workspace+string(os.PathSeparator)+"src", userRepos) } func addUser(username, password string) string {