mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-01 17:34:22 +00:00
refactor: retry file remove/rename when a file is busy and clean up os detection (#38588)
Rename functions "util.Remove" (remove.go) to "util.RemoveWithRetry" (file_retry.go) and add comments to clarify their behaviors, also add tests. Refactor callers: when no concurrent access (cmd cli, migration, app init, test), use "os.Xxx" directly. More details are in `modules/util/file_retry.go` By the way, clean up OS (windows) detection, make FileURLToPath test always run
This commit is contained in:
@@ -56,7 +56,7 @@ func (td *TempDir) MkdirTempRandom(elems ...string) (string, func(), error) {
|
||||
return "", nil, err
|
||||
}
|
||||
return dir, func() {
|
||||
if err := util.RemoveAll(dir); err != nil {
|
||||
if err := util.RemoveAllWithRetry(dir); err != nil {
|
||||
log.Error("Failed to remove temp directory %s: %v", dir, err)
|
||||
}
|
||||
}, nil
|
||||
@@ -75,7 +75,7 @@ func (td *TempDir) CreateTempFileRandom(elems ...string) (*os.File, func(), erro
|
||||
filename := f.Name()
|
||||
return f, func() {
|
||||
_ = f.Close()
|
||||
if err := util.Remove(filename); err != nil {
|
||||
if err := util.RemoveWithRetry(filename); err != nil {
|
||||
log.Error("Unable to remove temporary file: %s: Error: %v", filename, err)
|
||||
}
|
||||
}, err
|
||||
|
||||
Reference in New Issue
Block a user