diff options
Diffstat (limited to 'internal/git/housekeeping/clean_stale_data.go')
-rw-r--r-- | internal/git/housekeeping/clean_stale_data.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/git/housekeeping/clean_stale_data.go b/internal/git/housekeeping/clean_stale_data.go index 2cea9164a..931a97553 100644 --- a/internal/git/housekeeping/clean_stale_data.go +++ b/internal/git/housekeeping/clean_stale_data.go @@ -59,6 +59,7 @@ func (m *RepositoryManager) CleanStaleData(ctx context.Context, repo *localrepo. "reflocks": findStaleReferenceLocks, "packedrefslock": findPackedRefsLock, "packedrefsnew": findPackedRefsNew, + "serverinfo": findServerInfo, } { staleFiles, err := staleFileFinder(ctx, repoPath) if err != nil { @@ -364,6 +365,43 @@ func findPackedRefsNew(ctx context.Context, repoPath string) ([]string, error) { return findStaleFiles(repoPath, packedRefsNewGracePeriod, "packed-refs.new") } +// findServerInfo returns files generated by git-update-server-info(1). These files are only +// required to serve Git fetches via the dumb HTTP protocol, which we don't serve at all. It's thus +// safe to remove all of those files without a grace period. +func findServerInfo(ctx context.Context, repoPath string) ([]string, error) { + var serverInfoFiles []string + + for directory, basename := range map[string]string{ + filepath.Join(repoPath, "info"): "refs", + filepath.Join(repoPath, "objects", "info"): "packs", + } { + entries, err := os.ReadDir(directory) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + continue + } + + return nil, fmt.Errorf("reading info directory: %w", err) + } + + for _, entry := range entries { + if !entry.Type().IsRegular() { + continue + } + + // An exact match is the actual file we care about, while the latter pattern + // refers to the temporary files Git uses to write those files. + if entry.Name() != basename && !strings.HasPrefix(entry.Name(), basename+"_") { + continue + } + + serverInfoFiles = append(serverInfoFiles, filepath.Join(directory, entry.Name())) + } + } + + return serverInfoFiles, nil +} + // FixDirectoryPermissions does a recursive directory walk to look for // directories that cannot be accessed by the current user, and tries to // fix those with chmod. The motivating problem is that directories with mode |