zip 파일 unzip후 정리 추가
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user