This commit is contained in:
Liang Ding 2019-05-23 11:22:42 +08:00
parent 4a28d10a9d
commit 2e0f150cdb
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
1 changed files with 5 additions and 9 deletions

View File

@ -49,7 +49,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
locale := user.Locale locale := user.Locale
var args map[string]interface{} var args map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
result.Succ = false result.Succ = false
@ -58,9 +57,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
} }
sid := args["sid"].(string) sid := args["sid"].(string)
filePath := args["file"].(string) filePath := args["file"].(string)
if util.Go.IsAPI(filePath) || !session.CanAccess(uid, filePath) { if util.Go.IsAPI(filePath) || !session.CanAccess(uid, filePath) {
http.Error(w, "Forbidden", http.StatusForbidden) http.Error(w, "Forbidden", http.StatusForbidden)
@ -68,9 +65,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
} }
curDir := filepath.Dir(filePath) curDir := filepath.Dir(filePath)
fout, err := os.Create(filePath) fout, err := os.Create(filePath)
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
result.Succ = false result.Succ = false
@ -79,7 +74,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
} }
code := args["code"].(string) code := args["code"].(string)
fout.WriteString(code) fout.WriteString(code)
if err := fout.Close(); nil != err { if err := fout.Close(); nil != err {
@ -94,13 +88,15 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
suffix = ".exe" suffix = ".exe"
} }
goBuildArgs := []string{} var goBuildArgs []string
goBuildArgs = append(goBuildArgs, "build", "-i") goBuildArgs = append(goBuildArgs, "build")
goBuildArgs = append(goBuildArgs, user.BuildArgs(runtime.GOOS)...) goBuildArgs = append(goBuildArgs, user.BuildArgs(runtime.GOOS)...)
if !util.Str.Contains("-i", goBuildArgs) {
goBuildArgs = append(goBuildArgs, "-i")
}
cmd := exec.Command("go", goBuildArgs...) cmd := exec.Command("go", goBuildArgs...)
cmd.Dir = curDir cmd.Dir = curDir
setCmdEnv(cmd, uid) setCmdEnv(cmd, uid)
executable := filepath.Base(curDir) + suffix executable := filepath.Base(curDir) + suffix