mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-29 00:59:39 +09: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:
@@ -50,8 +50,8 @@ func rewriteAllPublicKeys(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
t.Close()
|
||||
if err := util.Remove(tmpPath); err != nil {
|
||||
_ = t.Close()
|
||||
if err := util.RemoveWithRetry(tmpPath); err != nil {
|
||||
log.Warn("Unable to remove temporary authorized keys file: %s: Error: %v", tmpPath, err)
|
||||
}
|
||||
}()
|
||||
@@ -74,6 +74,6 @@ func rewriteAllPublicKeys(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
t.Close()
|
||||
return util.Rename(tmpPath, fPath)
|
||||
_ = t.Close()
|
||||
return util.RenameWithRetry(tmpPath, fPath)
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ func rewriteAllPrincipalKeys(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
t.Close()
|
||||
os.Remove(tmpPath)
|
||||
_ = t.Close()
|
||||
_ = util.RemoveWithRetry(tmpPath)
|
||||
}()
|
||||
|
||||
if setting.SSH.AuthorizedPrincipalsBackup {
|
||||
@@ -83,8 +83,8 @@ func rewriteAllPrincipalKeys(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
t.Close()
|
||||
return util.Rename(tmpPath, fPath)
|
||||
_ = t.Close()
|
||||
return util.RenameWithRetry(tmpPath, fPath)
|
||||
}
|
||||
|
||||
func regeneratePrincipalKeys(ctx context.Context, t io.Writer) error {
|
||||
|
||||
Reference in New Issue
Block a user