A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package util
  5. import (
  6. "os"
  7. "syscall"
  8. "time"
  9. )
  10. // Remove removes the named file or (empty) directory with at most 5 attempts.
  11. func Remove(name string) error {
  12. var err error
  13. for i := 0; i < 5; i++ {
  14. err = os.Remove(name)
  15. if err == nil {
  16. break
  17. }
  18. unwrapped := err.(*os.PathError).Err
  19. if unwrapped == syscall.EBUSY || unwrapped == syscall.ENOTEMPTY || unwrapped == syscall.EPERM || unwrapped == syscall.EMFILE || unwrapped == syscall.ENFILE {
  20. // try again
  21. <-time.After(100 * time.Millisecond)
  22. continue
  23. }
  24. if unwrapped == syscall.ENOENT {
  25. // it's already gone
  26. return nil
  27. }
  28. }
  29. return err
  30. }
  31. // RemoveAll removes the named file or (empty) directory with at most 5 attempts.Remove
  32. func RemoveAll(name string) error {
  33. var err error
  34. for i := 0; i < 5; i++ {
  35. err = os.RemoveAll(name)
  36. if err == nil {
  37. break
  38. }
  39. unwrapped := err.(*os.PathError).Err
  40. if unwrapped == syscall.EBUSY || unwrapped == syscall.ENOTEMPTY || unwrapped == syscall.EPERM || unwrapped == syscall.EMFILE || unwrapped == syscall.ENFILE {
  41. // try again
  42. <-time.After(100 * time.Millisecond)
  43. continue
  44. }
  45. if unwrapped == syscall.ENOENT {
  46. // it's already gone
  47. return nil
  48. }
  49. }
  50. return err
  51. }