mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-01 10:40:38 +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:
@@ -188,7 +188,7 @@ func attemptMerge(ctx context.Context, file *unmergedFile, tmpBasePath string, t
|
||||
}
|
||||
root = strings.TrimSpace(root)
|
||||
defer func() {
|
||||
_ = util.Remove(filepath.Join(tmpBasePath, root))
|
||||
_ = util.RemoveWithRetry(filepath.Join(tmpBasePath, root))
|
||||
}()
|
||||
|
||||
base, _, err := gitcmd.NewCommand("unpack-file").AddDynamicArguments(file.stage2.sha).WithRepo(tmpGitRepo).RunStdString(ctx)
|
||||
@@ -197,7 +197,7 @@ func attemptMerge(ctx context.Context, file *unmergedFile, tmpBasePath string, t
|
||||
}
|
||||
base = strings.TrimSpace(filepath.Join(tmpBasePath, base))
|
||||
defer func() {
|
||||
_ = util.Remove(base)
|
||||
_ = util.RemoveWithRetry(base)
|
||||
}()
|
||||
head, _, err := gitcmd.NewCommand("unpack-file").AddDynamicArguments(file.stage3.sha).WithRepo(tmpGitRepo).RunStdString(ctx)
|
||||
if err != nil {
|
||||
@@ -205,7 +205,7 @@ func attemptMerge(ctx context.Context, file *unmergedFile, tmpBasePath string, t
|
||||
}
|
||||
head = strings.TrimSpace(head)
|
||||
defer func() {
|
||||
_ = util.Remove(filepath.Join(tmpBasePath, head))
|
||||
_ = util.RemoveWithRetry(filepath.Join(tmpBasePath, head))
|
||||
}()
|
||||
|
||||
// now git merge-file annoyingly takes a different order to the merge-tree ...
|
||||
|
||||
Reference in New Issue
Block a user