diff --git a/__debug_bin782867005 b/__debug_bin782867005 new file mode 100755 index 0000000..fdb8caf Binary files /dev/null and b/__debug_bin782867005 differ diff --git a/pkg/utils/file/file.go b/pkg/utils/file/file.go index e67a8e4..6a10144 100644 --- a/pkg/utils/file/file.go +++ b/pkg/utils/file/file.go @@ -77,6 +77,22 @@ func RMDir(src string) error { 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 func Open(name string, flag int, perm os.FileMode) (*os.File, error) { f, err := os.OpenFile(name, flag, perm) diff --git a/route/v1/file.go b/route/v1/file.go index 4cf3bfc..98bd2af 100644 --- a/route/v1/file.go +++ b/route/v1/file.go @@ -581,12 +581,12 @@ func PostFileUpload(c *gin.Context) { c.JSON(http.StatusInternalServerError, model.Result{Success: common_err.SERVICE_ERROR, Message: err.Error()}) return } - - if err := file.RMDir(tempDir); err != nil { - logger.Error("error when trying to remove `"+tempDir+"`", zap.Error(err)) - c.JSON(http.StatusInternalServerError, model.Result{Success: common_err.SERVICE_ERROR, Message: err.Error()}) - return - } + go func() { + time.Sleep(11 * time.Second) + if err := file.RMDir(tempDir); err != nil { + logger.Error("error when trying to remove `"+tempDir+"`", zap.Error(err)) + } + }() } } else { out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o644)