From e9370513c29199a6d82b202be8b32a8cfa7776d4 Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 26 Sep 2024 13:18:32 +0900 Subject: [PATCH] =?UTF-8?q?zip=20=ED=8C=8C=EC=9D=BC=20unzip=ED=9B=84=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/http_handler.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/http_handler.go b/server/http_handler.go index 19cc4b6..f54354d 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -140,25 +140,27 @@ func (h *houstonHandler) RegisterHandlers(serveMux gocommon.ServerMuxInterface, filename := r.Header.Get("Houston-Service-Filename") dir := path.Join(h.downloadPath, name, version) if err := os.MkdirAll(dir, 0775); err == nil { - zipfile, _ := os.Create(path.Join(dir, filename)) - logger.Println("file uploaded :", zipfile) - if zipfile != nil { - if _, err = io.Copy(zipfile, r.Body); err != nil { + filepath := path.Join(dir, filename) + localfile, _ := os.Create(filepath) + logger.Println("file uploaded :", localfile) + if localfile != nil { + 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, _ := zipfile.Stat() - zipreader, _ := zip.NewReader(zipfile, stat.Size()) + 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() } - defer os.Remove(path.Join(dir, filename)) + os.Remove(filepath) } } - zipfile.Close() } else { w.WriteHeader(http.StatusInternalServerError) }