로그 파일을 압축하지 않고 하나씩 업로드

This commit is contained in:
2024-11-06 16:46:45 +09:00
parent 9632dc7755
commit 99e1007012
4 changed files with 136 additions and 73 deletions

View File

@ -1,7 +1,6 @@
package server
import (
"archive/zip"
"crypto/md5"
"encoding/hex"
"fmt"
@ -141,25 +140,13 @@ func (h *houstonHandler) RegisterHandlers(serveMux gocommon.ServerMuxInterface,
dir := path.Join(h.downloadPath, name, version)
if err := os.MkdirAll(dir, 0775); err == nil {
filepath := path.Join(dir, filename)
localfile, _ := os.Create(filepath)
// filepath가 이미 있으면 append
localfile, _ := os.OpenFile(filepath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
logger.Println("file uploaded :", localfile)
if localfile != nil {
defer localfile.Close()
if _, err = io.Copy(localfile, r.Body); err != nil {
w.WriteHeader(http.StatusInternalServerError)
} else {
localfile.Close()
localfile, _ = os.Open(filepath)
if strings.HasSuffix(filename, ".zip") {
stat, _ := localfile.Stat()
zipreader, _ := zip.NewReader(localfile, stat.Size())
for _, f := range zipreader.File {
file, _ := os.Create(path.Join(dir, f.Name))
comp, _ := f.Open()
io.Copy(file, comp)
file.Close()
}
os.Remove(filepath)
}
}
} else {
w.WriteHeader(http.StatusInternalServerError)