mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-02 05:09:57 +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:
+3
-8
@@ -72,16 +72,11 @@ func (h *Hook) Name() string {
|
||||
// Update updates hook settings.
|
||||
func (h *Hook) Update() error {
|
||||
if len(strings.TrimSpace(h.Content)) == 0 {
|
||||
exist, err := util.IsExist(h.path)
|
||||
if err != nil {
|
||||
// empty content means to remove the file
|
||||
err := util.RemoveWithRetry(h.path)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
if exist {
|
||||
err := util.Remove(h.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
h.IsActive = false
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user