Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-09-28 16:06:43 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-09-29 12:24:15 +0300
commitb9bab0a579e409289183f2d6dc107e5ac938056a (patch)
tree8434d773d91992d59111d566d522146b381909c4
parent3415696d0d9e1d2eafd9cd96865dc3e25c575046 (diff)
repository: Convert keep-around ref cleanup to use `os.ReadDir()`
Go 1.15 has deprecated the `ioutil` package and made replacements available in the `io` or `os` packages. While we have already migrated most callsites away, one notable omission was `ioutil.ReadDir()` as this function doesn't have an exact replacement: the new `os.ReadDir()` function does not stat all directory entries anymore. Refactor the cleanup of stale keep-around references in the `GarbageCollect` RPC to use the new function.
-rw-r--r--internal/gitaly/service/repository/gc.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/internal/gitaly/service/repository/gc.go b/internal/gitaly/service/repository/gc.go
index 3acdaa6a0..a06a411eb 100644
--- a/internal/gitaly/service/repository/gc.go
+++ b/internal/gitaly/service/repository/gc.go
@@ -1,11 +1,10 @@
package repository
-//nolint:depguard
import (
"context"
"errors"
"fmt"
- "io/ioutil"
+ "io/fs"
"os"
"path/filepath"
@@ -107,7 +106,7 @@ func (s *server) cleanupKeepArounds(ctx context.Context, repo *localrepo.Repo) e
keepAroundsPrefix := "refs/keep-around"
keepAroundsPath := filepath.Join(repoPath, keepAroundsPrefix)
- refInfos, err := ioutil.ReadDir(keepAroundsPath)
+ refEntries, err := os.ReadDir(keepAroundsPath)
if os.IsNotExist(err) {
return nil
}
@@ -115,11 +114,24 @@ func (s *server) cleanupKeepArounds(ctx context.Context, repo *localrepo.Repo) e
return err
}
- for _, info := range refInfos {
- if info.IsDir() {
+ for _, entry := range refEntries {
+ if entry.IsDir() {
continue
}
+ info, err := entry.Info()
+ if err != nil {
+ // Even though the reference has disappeared we know its name
+ // and thus the object hash it is supposed to point to. So
+ // while we technically could try to fix it, we don't as
+ // we seem to be racing with a concurrent process.
+ if errors.Is(err, fs.ErrNotExist) {
+ continue
+ }
+
+ return fmt.Errorf("statting keep-around ref: %w", err)
+ }
+
refName := fmt.Sprintf("%s/%s", keepAroundsPrefix, info.Name())
path := filepath.Join(repoPath, keepAroundsPrefix, info.Name())