[1.3] 신고
- 데모 파일 압축해서 업로드하도록 수정
This commit is contained in:
@ -1,12 +1,14 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -126,11 +128,58 @@ func validatePipeReq(command, param, receivedHash string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleStdOutUploadRequest(hc *houstonClient, meta *procmeta, param string) error {
|
func handleStdOutUploadRequest(hc *houstonClient, meta *procmeta, param string) error {
|
||||||
uploadFullPath := param
|
if uploadZipPath, err := compressFile(param); err != nil {
|
||||||
if _, err := os.Stat(uploadFullPath); err != nil {
|
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
hc.uploadToAppendFile(uploadFullPath, meta.name, meta.version, filepath.Base(uploadFullPath))
|
hc.uploadToAppendFile(uploadZipPath, meta.name, meta.version, filepath.Base(uploadZipPath))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func compressFile(fullPath string) (string, error) {
|
||||||
|
ext := filepath.Ext(fullPath)
|
||||||
|
zipFullPath := fullPath[:len(fullPath)-len(ext)] + ".zip"
|
||||||
|
|
||||||
|
// Create
|
||||||
|
newZipFile, err := os.Create(zipFullPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer newZipFile.Close()
|
||||||
|
zipWriter := zip.NewWriter(newZipFile)
|
||||||
|
defer zipWriter.Close()
|
||||||
|
|
||||||
|
// Open
|
||||||
|
fileToZip, err := os.Open(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer fileToZip.Close()
|
||||||
|
fileToZipInfo, err := fileToZip.Stat()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zip
|
||||||
|
fileToZipHeader, err := zip.FileInfoHeader(fileToZipInfo)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
fileToZipHeader.Name = fileToZipInfo.Name()
|
||||||
|
fileToZipHeader.Method = zip.Deflate
|
||||||
|
fileToZipWriter, err := zipWriter.CreateHeader(fileToZipHeader)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
_, err = io.Copy(fileToZipWriter, fileToZip)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove
|
||||||
|
err = os.Remove(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return zipFullPath, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user