@@ -11,17 +11,15 @@ import (
11
11
"io"
12
12
"os"
13
13
"os/exec"
14
- "path"
15
14
"regexp"
16
15
"strings"
17
16
"time"
18
17
19
18
"code.gitea.io/gitea/models"
20
19
"code.gitea.io/gitea/modules/git"
20
+ "code.gitea.io/gitea/modules/log"
21
21
"code.gitea.io/gitea/modules/process"
22
22
"code.gitea.io/gitea/modules/setting"
23
-
24
- "github.com/Unknwon/com"
25
23
)
26
24
27
25
// TemporaryUploadRepository is a type to wrap our upload repositories as a shallow clone
@@ -33,22 +31,18 @@ type TemporaryUploadRepository struct {
33
31
34
32
// NewTemporaryUploadRepository creates a new temporary upload repository
35
33
func NewTemporaryUploadRepository (repo * models.Repository ) (* TemporaryUploadRepository , error ) {
36
- timeStr := com .ToStr (time .Now ().Nanosecond ()) // SHOULD USE SOMETHING UNIQUE
37
- basePath := path .Join (models .LocalCopyPath (), "upload-" + timeStr + ".git" )
38
- if err := os .MkdirAll (path .Dir (basePath ), os .ModePerm ); err != nil {
39
- return nil , fmt .Errorf ("failed to create dir %s: %v" , basePath , err )
40
- }
41
- if repo .RepoPath () == "" {
42
- return nil , fmt .Errorf ("no path to repository on system" )
34
+ basePath , err := models .CreateTemporaryPath ("upload" )
35
+ if err != nil {
36
+ return nil , err
43
37
}
44
38
t := & TemporaryUploadRepository {repo : repo , basePath : basePath }
45
39
return t , nil
46
40
}
47
41
48
42
// Close the repository cleaning up all files
49
43
func (t * TemporaryUploadRepository ) Close () {
50
- if _ , err := os . Stat (t .basePath ); ! os . IsNotExist ( err ) {
51
- os . RemoveAll ( t .basePath )
44
+ if err := models . RemoveTemporaryPath (t .basePath ); err != nil {
45
+ log . Error ( "Failed to remove temporary path %s: %v" , t .basePath , err )
52
46
}
53
47
}
54
48
0 commit comments