@@ -6,15 +6,13 @@ package models
6
6
7
7
import (
8
8
"fmt"
9
+ "io/ioutil"
9
10
"os"
10
11
"path"
11
12
"path/filepath"
12
- "time"
13
13
14
14
"code.gitea.io/gitea/modules/log"
15
15
"code.gitea.io/gitea/modules/setting"
16
-
17
- "github.com/unknwon/com"
18
16
)
19
17
20
18
// LocalCopyPath returns the local repository temporary copy path.
@@ -27,11 +25,15 @@ func LocalCopyPath() string {
27
25
28
26
// CreateTemporaryPath creates a temporary path
29
27
func CreateTemporaryPath (prefix string ) (string , error ) {
30
- timeStr := com .ToStr (time .Now ().Nanosecond ()) // SHOULD USE SOMETHING UNIQUE
31
- basePath := path .Join (LocalCopyPath (), prefix + "-" + timeStr + ".git" )
32
- if err := os .MkdirAll (filepath .Dir (basePath ), os .ModePerm ); err != nil {
33
- log .Error ("Unable to create temporary directory: %s (%v)" , basePath , err )
34
- return "" , fmt .Errorf ("Failed to create dir %s: %v" , basePath , err )
28
+ if err := os .MkdirAll (LocalCopyPath (), os .ModePerm ); err != nil {
29
+ log .Error ("Unable to create localcopypath directory: %s (%v)" , LocalCopyPath (), err )
30
+ return "" , fmt .Errorf ("Failed to create localcopypath directory %s: %v" , LocalCopyPath (), err )
31
+ }
32
+ basePath , err := ioutil .TempDir (LocalCopyPath (), prefix + "-*.git" )
33
+ if err != nil {
34
+ log .Error ("Unable to create temporary directory: %s-*.git (%v)" , prefix , err )
35
+ return "" , fmt .Errorf ("Failed to create dir %s-*.git: %v" , prefix , err )
36
+
35
37
}
36
38
return basePath , nil
37
39
}
0 commit comments