File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright 2025 The Gitea Authors. All rights reserved. 
2+ // SPDX-License-Identifier: MIT 
3+ 
4+ package  gitrepo
5+ 
6+ import  (
7+ 	"context" 
8+ 	"os" 
9+ 	"path/filepath" 
10+ 	"time" 
11+ )
12+ 
13+ var  lockFiles  =  []string {
14+ 	"config.lock" ,
15+ 	"objects/info/commit-graphs/commit-graph-chain.lock" ,
16+ }
17+ 
18+ // CleanupRepo cleans up the repository by removing unnecessary lock files. 
19+ func  CleanupRepo (ctx  context.Context , repo  Repository ) error  {
20+ 	return  CleanFixedFileLocks (ctx , repo , time .Now ())
21+ }
22+ 
23+ // CleanFixedFileLocks removes lock files that haven't been modified since the last update. 
24+ func  CleanFixedFileLocks (ctx  context.Context , repo  Repository , lastUpdated  time.Time ) error  {
25+ 	for  _ , lockFile  :=  range  lockFiles  {
26+ 		p  :=  filepath .Join (repoPath (repo ), lockFile )
27+ 		fInfo , err  :=  os .Stat (p )
28+ 		if  err  !=  nil  {
29+ 			if  os .IsNotExist (err ) {
30+ 				continue 
31+ 			}
32+ 			return  err 
33+ 		}
34+ 
35+ 		if  fInfo .ModTime ().Before (lastUpdated ) {
36+ 			if  err  :=  os .Remove (p ); err  !=  nil  {
37+ 				return  err 
38+ 			}
39+ 		}
40+ 	}
41+ 	return  nil 
42+ }
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments