diff --git a/client/client.go b/client/client.go index 736e196..1498a93 100644 --- a/client/client.go +++ b/client/client.go @@ -34,9 +34,9 @@ import ( ) type runcommand struct { - Exec string `json:"exec"` - Args []string `json:"args"` - Version string `json:"version"` + Exec string `json:"exec"` + Args []string `json:"args"` + Version string `json:"version"` } type clientConfig struct { @@ -98,9 +98,10 @@ func (pm *procmeta) setState(s protos.ProcessState) { } type uploadRequest struct { - filePath string - name string - version string + filePath string + name string + version string + uploadedFileName string } type houstonClient struct { @@ -503,7 +504,7 @@ func NewClient(standalone bool) (HoustonClient, error) { return hc, nil } -func uploadSafe(url, filePath, name, version string) error { +func uploadSafe(url, filePath, name, version, uploadedFileName string) error { defer func() { r := recover() if r != nil { @@ -537,7 +538,10 @@ func uploadSafe(url, filePath, name, version string) error { // createTime := file. httpreq.Header.Set("Houston-Service-Name", name) httpreq.Header.Set("Houston-Service-Version", version) - httpreq.Header.Set("Houston-Service-Filename", t.BirthTime().UTC().Format(time.DateOnly)+"."+hn+path.Ext(filePath)) + if len(uploadedFileName) == 0 { + uploadedFileName = t.BirthTime().UTC().Format(time.DateOnly) + "." + hn + path.Ext(filePath) + } + httpreq.Header.Set("Houston-Service-Filename", uploadedFileName) httpreq.Header.Set("Content-Type", "application/zip") resp, err := http.DefaultClient.Do(httpreq) if err != nil { @@ -581,7 +585,7 @@ func (hc *houstonClient) Start() { url := hc.config.HttpAddress + "/upload" for req := range hc.uploadChan { logger.Println("uploadSafe :", req) - err := uploadSafe(url, req.filePath, req.name, req.version) + err := uploadSafe(url, req.filePath, req.name, req.version, req.uploadedFileName) if err != nil { logger.Println("uploadSafe return err :", err) } @@ -630,8 +634,8 @@ func (hc *houstonClient) Start() { logger.Println("autorun success :", sr) } } - } } + } for { select { diff --git a/client/houston_pipe_req.go b/client/houston_pipe_req.go index f07a1bc..df220f4 100644 --- a/client/houston_pipe_req.go +++ b/client/houston_pipe_req.go @@ -8,6 +8,7 @@ import ( "encoding/hex" "errors" "os" + "path/filepath" "strings" ) @@ -129,7 +130,7 @@ func handleStdOutUploadRequest(hc *houstonClient, meta *procmeta, param string) if _, err := os.Stat(uploadFullPath); err != nil { return err } else { - hc.uploadToAppendFile(uploadFullPath, meta.name, meta.version) + hc.uploadToAppendFile(uploadFullPath, meta.name, meta.version, filepath.Base(uploadFullPath)) } return nil } diff --git a/client/operation.go b/client/operation.go index d5d256c..db01c10 100644 --- a/client/operation.go +++ b/client/operation.go @@ -44,11 +44,12 @@ func lastExecutionArgs(verpath string) []string { return out } -func (hc *houstonClient) uploadToAppendFile(filePath string, name string, version string) { +func (hc *houstonClient) uploadToAppendFile(filePath string, name string, version string, uploadedFileName string) { hc.uploadChan <- uploadRequest{ - filePath: filePath, - name: name, - version: version, + filePath: filePath, + name: name, + version: version, + uploadedFileName: uploadedFileName, } }