mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-22 13:18:29 -04:00
Re-attempt to delete temporary upload if the file is locked by another process (#12447)
Replace all calls to os.Remove/os.RemoveAll by retrying util.Remove/util.RemoveAll and remove circular dependencies from util. Fix #12339 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
faa676cc8b
commit
74bd9691c6
60 changed files with 304 additions and 202 deletions
|
@ -1440,7 +1440,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
|
|||
// Create/Remove git-daemon-export-ok for git-daemon...
|
||||
daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
|
||||
if repo.IsPrivate && com.IsExist(daemonExportFile) {
|
||||
if err = os.Remove(daemonExportFile); err != nil {
|
||||
if err = util.Remove(daemonExportFile); err != nil {
|
||||
log.Error("Failed to remove %s: %v", daemonExportFile, err)
|
||||
}
|
||||
} else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
|
||||
|
@ -1708,7 +1708,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
|||
if len(repo.Avatar) > 0 {
|
||||
avatarPath := repo.CustomAvatarPath()
|
||||
if com.IsExist(avatarPath) {
|
||||
if err := os.Remove(avatarPath); err != nil {
|
||||
if err := util.Remove(avatarPath); err != nil {
|
||||
return fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
|
||||
}
|
||||
}
|
||||
|
@ -1852,7 +1852,7 @@ func DeleteRepositoryArchives(ctx context.Context) error {
|
|||
return ErrCancelledf("before deleting repository archives for %s", repo.FullName())
|
||||
default:
|
||||
}
|
||||
return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives"))
|
||||
return util.RemoveAll(filepath.Join(repo.RepoPath(), "archives"))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1911,7 +1911,7 @@ func deleteOldRepositoryArchives(ctx context.Context, olderThan time.Duration, i
|
|||
}
|
||||
toDelete := filepath.Join(path, info.Name())
|
||||
// This is a best-effort purge, so we do not check error codes to confirm removal.
|
||||
if err = os.Remove(toDelete); err != nil {
|
||||
if err = util.Remove(toDelete); err != nil {
|
||||
log.Trace("Unable to delete %s, but proceeding: %v", toDelete, err)
|
||||
}
|
||||
}
|
||||
|
@ -2280,7 +2280,7 @@ func (repo *Repository) UploadAvatar(data []byte) error {
|
|||
}
|
||||
|
||||
if len(oldAvatarPath) > 0 && oldAvatarPath != repo.CustomAvatarPath() {
|
||||
if err := os.Remove(oldAvatarPath); err != nil {
|
||||
if err := util.Remove(oldAvatarPath); err != nil {
|
||||
return fmt.Errorf("UploadAvatar: Failed to remove old repo avatar %s: %v", oldAvatarPath, err)
|
||||
}
|
||||
}
|
||||
|
@ -2311,7 +2311,7 @@ func (repo *Repository) DeleteAvatar() error {
|
|||
}
|
||||
|
||||
if _, err := os.Stat(avatarPath); err == nil {
|
||||
if err := os.Remove(avatarPath); err != nil {
|
||||
if err := util.Remove(avatarPath); err != nil {
|
||||
return fmt.Errorf("DeleteAvatar: Failed to remove %s: %v", avatarPath, err)
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue