mirror of
https://github.com/go-gitea/gitea.git
synced 2026-01-07 08:35:55 +01:00
Cleanup lock files
This commit is contained in:
parent
8a534132c8
commit
a6ac8f0611
42
modules/gitrepo/cleanup.go
Normal file
42
modules/gitrepo/cleanup.go
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package gitrepo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
var lockFiles = []string{
|
||||
"config.lock",
|
||||
"objects/info/commit-graphs/commit-graph-chain.lock",
|
||||
}
|
||||
|
||||
// CleanupRepo cleans up the repository by removing unnecessary lock files.
|
||||
func CleanupRepo(ctx context.Context, repo Repository) error {
|
||||
return CleanFixedFileLocks(ctx, repo, time.Now())
|
||||
}
|
||||
|
||||
// CleanFixedFileLocks removes lock files that haven't been modified since the last update.
|
||||
func CleanFixedFileLocks(ctx context.Context, repo Repository, lastUpdated time.Time) error {
|
||||
for _, lockFile := range lockFiles {
|
||||
p := filepath.Join(repoPath(repo), lockFile)
|
||||
fInfo, err := os.Stat(p)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if fInfo.ModTime().Before(lastUpdated) {
|
||||
if err := os.Remove(p); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user