Skip to content

Commit 2f79099

Browse files
committed
Fix for external files
1 parent 843d46c commit 2f79099

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

conn.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"fmt"
1616
"io/ioutil"
1717
"net/http"
18+
"os"
1819
"path/filepath"
1920

2021
log "github.com/Sirupsen/logrus"
@@ -119,13 +120,27 @@ func uploadHandler(c *gin.Context) {
119120
var filePaths []string
120121
filePaths = append(filePaths, filePath)
121122

123+
tmpdir, err := ioutil.TempDir("", "extrafiles")
124+
if err != nil {
125+
c.String(http.StatusBadRequest, err.Error())
126+
return
127+
}
128+
122129
for _, extraFile := range data.ExtraFiles {
123-
path := filepath.Join(filepath.Dir(filePath), extraFile.Filename)
130+
path := filepath.Join(tmpdir, extraFile.Filename)
124131
filePaths = append(filePaths, path)
125132
log.Printf("Saving %s on %s", extraFile.Filename, path)
133+
134+
err = os.MkdirAll(filepath.Dir(path), 0744)
135+
if err != nil {
136+
c.String(http.StatusBadRequest, err.Error())
137+
return
138+
}
139+
126140
err := ioutil.WriteFile(path, extraFile.Hex, 0644)
127141
if err != nil {
128-
log.Printf(err.Error())
142+
c.String(http.StatusBadRequest, err.Error())
143+
return
129144
}
130145
}
131146

@@ -135,7 +150,7 @@ func uploadHandler(c *gin.Context) {
135150

136151
go func() {
137152
// Resolve commandline
138-
commandline, err := upload.PartiallyResolve(data.Board, filePath, data.Commandline, data.Extra, &Tools)
153+
commandline, err := upload.PartiallyResolve(data.Board, filePath, tmpdir, data.Commandline, data.Extra, &Tools)
139154
if err != nil {
140155
send(map[string]string{uploadStatusStr: "Error", "Msg": err.Error()})
141156
return

upload/upload.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ type Extra struct {
5151

5252
// PartiallyResolve replaces some symbols in the commandline with the appropriate values
5353
// it can return an error when looking a variable in the Locater
54-
func PartiallyResolve(board, file, commandline string, extra Extra, t Locater) (string, error) {
54+
func PartiallyResolve(board, file, platformPath, commandline string, extra Extra, t Locater) (string, error) {
5555
commandline = strings.Replace(commandline, "{build.path}", filepath.ToSlash(filepath.Dir(file)), -1)
5656
commandline = strings.Replace(commandline, "{build.project_name}", strings.TrimSuffix(filepath.Base(file), filepath.Ext(filepath.Base(file))), -1)
5757
commandline = strings.Replace(commandline, "{network.password}", extra.Auth.Password, -1)
58+
commandline = strings.Replace(commandline, "{runtime.platform.path}", platformPath, -1)
5859

5960
if extra.Verbose == true {
6061
commandline = strings.Replace(commandline, "{upload.verbose}", extra.ParamsVerbose, -1)

0 commit comments

Comments
 (0)