delay delete temp file
This commit is contained in:
parent
b17bff68dd
commit
657cbe5c41
Binary file not shown.
|
@ -77,6 +77,22 @@ func RMDir(src string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RemoveAll(dir string) error {
|
||||||
|
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
return os.Remove(path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.Remove(dir)
|
||||||
|
}
|
||||||
|
|
||||||
// Open a file according to a specific mode
|
// Open a file according to a specific mode
|
||||||
func Open(name string, flag int, perm os.FileMode) (*os.File, error) {
|
func Open(name string, flag int, perm os.FileMode) (*os.File, error) {
|
||||||
f, err := os.OpenFile(name, flag, perm)
|
f, err := os.OpenFile(name, flag, perm)
|
||||||
|
|
|
@ -581,12 +581,12 @@ func PostFileUpload(c *gin.Context) {
|
||||||
c.JSON(http.StatusInternalServerError, model.Result{Success: common_err.SERVICE_ERROR, Message: err.Error()})
|
c.JSON(http.StatusInternalServerError, model.Result{Success: common_err.SERVICE_ERROR, Message: err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
go func() {
|
||||||
if err := file.RMDir(tempDir); err != nil {
|
time.Sleep(11 * time.Second)
|
||||||
logger.Error("error when trying to remove `"+tempDir+"`", zap.Error(err))
|
if err := file.RMDir(tempDir); err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, model.Result{Success: common_err.SERVICE_ERROR, Message: err.Error()})
|
logger.Error("error when trying to remove `"+tempDir+"`", zap.Error(err))
|
||||||
return
|
}
|
||||||
}
|
}()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o644)
|
out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o644)
|
||||||
|
|
Loading…
Reference in New Issue