@@ -6,38 +6,44 @@ package repository
66import (
77 "fmt"
88 "os"
9- "path"
109 "path/filepath"
1110
1211 "code.gitea.io/gitea/modules/log"
1312 "code.gitea.io/gitea/modules/setting"
1413 "code.gitea.io/gitea/modules/util"
1514)
1615
17- // LocalCopyPath returns the local repository temporary copy path.
18- func LocalCopyPath () string {
19- if filepath .IsAbs (setting .Repository .Local .LocalCopyPath ) {
20- return setting .Repository .Local .LocalCopyPath
16+ // localCopyPath returns the local repository temporary copy path.
17+ func localCopyPath () string {
18+ return filepath .Join (setting .TempDir (), "local-repo" )
19+ }
20+
21+ func CleanUpTemporaryPaths () {
22+ if err := util .RemoveAll (localCopyPath ()); err != nil {
23+ log .Error ("Unable to remove local repository temporary copy path: %s (%v)" , localCopyPath (), err )
2124 }
22- return path .Join (setting .AppDataPath , setting .Repository .Local .LocalCopyPath )
2325}
2426
2527// CreateTemporaryPath creates a temporary path
26- func CreateTemporaryPath (prefix string ) (string , error ) {
27- if err := os .MkdirAll (LocalCopyPath (), os .ModePerm ); err != nil {
28- log .Error ("Unable to create localcopypath directory: %s (%v)" , LocalCopyPath (), err )
29- return "" , fmt .Errorf ("Failed to create localcopypath directory %s: %w" , LocalCopyPath (), err )
28+ func CreateTemporaryPath (prefix string ) (string , func (), error ) {
29+ if err := os .MkdirAll (localCopyPath (), os .ModePerm ); err != nil {
30+ log .Error ("Unable to create localcopypath directory: %s (%v)" , localCopyPath (), err )
31+ return "" , func () {}, fmt .Errorf ("failed to create localcopypath directory %s: %w" , localCopyPath (), err )
3032 }
31- basePath , err := os .MkdirTemp (LocalCopyPath (), prefix + ".git" )
33+ basePath , err := os .MkdirTemp (localCopyPath (), prefix + ".git" )
3234 if err != nil {
3335 log .Error ("Unable to create temporary directory: %s-*.git (%v)" , prefix , err )
34- return "" , fmt .Errorf ("Failed to create dir %s-*.git: %w" , prefix , err )
36+ return "" , func () {}, fmt .Errorf ("failed to create dir %s-*.git: %w" , prefix , err )
3537 }
36- return basePath , nil
38+ return basePath , func () {
39+ if err := removeTemporaryPath (basePath ); err != nil {
40+ log .Error ("Unable to remove temporary directory: %s (%v)" , basePath , err )
41+ }
42+ }, nil
3743}
3844
39- // RemoveTemporaryPath removes the temporary path
40- func RemoveTemporaryPath (basePath string ) error {
45+ // removeTemporaryPath removes the temporary path
46+ func removeTemporaryPath (basePath string ) error {
4147 if _ , err := os .Stat (basePath ); ! os .IsNotExist (err ) {
4248 return util .RemoveAll (basePath )
4349 }
0 commit comments