Browse Source

修改了zipfiles.go中ZipFiles函数可能会造成的goroutine泄露

main
songzhibin97 4 years ago
parent
commit
e902d0a156
  1. 15
      server/utils/zipfiles.go

15
server/utils/zipfiles.go

@ -20,15 +20,15 @@ func ZipFiles(filename string, files []string, oldform, newform string) error {
// 把files添加到zip中 // 把files添加到zip中
for _, file := range files { for _, file := range files {
zipfile, err := os.Open(file)
err = func(file string) error {
zipFile, err := os.Open(file)
if err != nil { if err != nil {
return err return err
} }
defer zipfile.Close()
defer zipFile.Close()
// 获取file的基础信息 // 获取file的基础信息
info, err := zipfile.Stat()
info, err := zipFile.Stat()
if err != nil { if err != nil {
return err return err
} }
@ -49,7 +49,12 @@ func ZipFiles(filename string, files []string, oldform, newform string) error {
if err != nil { if err != nil {
return err return err
} }
if _, err = io.Copy(writer, zipfile); err != nil {
if _, err = io.Copy(writer, zipFile); err != nil {
return err
}
return nil
}(file)
if err != nil {
return err return err
} }
} }

Loading…
Cancel
Save