mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-09 22:18:39 +02:00
fix: correct RemoveWithRetry error handling (#39619)
* Fix #39618 * Follow up #38588 * Remove unrelated errors
This commit is contained in:
1 parent
1264072754
commit
fc1f0dbec4
2 files changed
+7
-3
No files matched your search
@@ -119,7 +119,7 @@ func (l *LocalStorage) Stat(path string) (os.FileInfo, error) {
|
|||||||
|
|
||||||
func (l *LocalStorage) deleteEmptyParentDirs(localFullPath string) {
|
func (l *LocalStorage) deleteEmptyParentDirs(localFullPath string) {
|
||||||
for parent := filepath.Dir(localFullPath); len(parent) > len(l.dir); parent = filepath.Dir(parent) {
|
for parent := filepath.Dir(localFullPath); len(parent) > len(l.dir); parent = filepath.Dir(parent) {
|
||||||
if err := util.RemoveWithRetry(parent); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(parent); err != nil && !os.IsNotExist(err) {
|
||||||
// since the target file has been deleted, parent dir error is not related to the file deletion itself.
|
// since the target file has been deleted, parent dir error is not related to the file deletion itself.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,19 +15,23 @@ import (
|
|||||||
// * the "cat-batch" git process might be running in a goroutine
|
// * the "cat-batch" git process might be running in a goroutine
|
||||||
// * there can be a data-race between the "cat-batch" git process cancel+exit and the repo rename
|
// * there can be a data-race between the "cat-batch" git process cancel+exit and the repo rename
|
||||||
// So we need to retry the rename/remove operation for a few times when the "cat-batch" git process is exiting.
|
// So we need to retry the rename/remove operation for a few times when the "cat-batch" git process is exiting.
|
||||||
// ref: https://github.com/go-gitea/gitea/issues/16427, https://github.com/go-gitea/gitea/issues/16475, https://github.com/go-gitea/gitea/pull/16479
|
// ref: https://github.com/go-gitea/gitea/issues/16427, https://github.com/go-gitea/gitea/issues/16475
|
||||||
|
// ref: https://github.com/go-gitea/gitea/pull/16435, https://github.com/go-gitea/gitea/pull/16479
|
||||||
// Also some similar problems when removing a file, e.g.: https://github.com/go-gitea/gitea/issues/12339
|
// Also some similar problems when removing a file, e.g.: https://github.com/go-gitea/gitea/issues/12339
|
||||||
//
|
//
|
||||||
// Usually, if no concurrent access to a file, use "os.Xxx", otherwise, use "util.XxxWithRetry"
|
// Usually, if no concurrent access to a file, use "os.Xxx", otherwise, use "util.XxxWithRetry"
|
||||||
|
|
||||||
func retryWhenFileBusyInternal(count int, delay time.Duration, f func() error) (err error) {
|
func retryWhenFileBusyInternal(count int, delay time.Duration, f func() error) (err error) {
|
||||||
|
// Windows: an opened file without share flags can't be removed or renamed:
|
||||||
|
// Error code 32: The process cannot access the file because it is being used by another process.
|
||||||
|
// Also, Error code 16 (EBUSY) happens to be "The directory cannot be removed" (the directory is used as a current directory by a process)
|
||||||
const errWindowsSharingViolationError = syscall.Errno(32)
|
const errWindowsSharingViolationError = syscall.Errno(32)
|
||||||
for range count {
|
for range count {
|
||||||
err = f()
|
err = f()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
isErrBusy := errors.Is(err, syscall.EBUSY) || errors.Is(err, syscall.ENOTEMPTY) || errors.Is(err, syscall.EPERM) || errors.Is(err, syscall.EMFILE) || errors.Is(err, syscall.ENFILE)
|
isErrBusy := errors.Is(err, syscall.EBUSY)
|
||||||
isErrBusy = isErrBusy || (isOSWindows && errors.Is(err, errWindowsSharingViolationError))
|
isErrBusy = isErrBusy || (isOSWindows && errors.Is(err, errWindowsSharingViolationError))
|
||||||
if !isErrBusy {
|
if !isErrBusy {
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in new issue
Block a user