Skip to content

Commit 9e24284

Browse files
committed
Use ioutil.TempDir
1 parent f2f0a41 commit 9e24284

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

models/helper_directory.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ package models
66

77
import (
88
"fmt"
9+
"io/ioutil"
910
"os"
1011
"path"
1112
"path/filepath"
12-
"time"
1313

1414
"code.gitea.io/gitea/modules/log"
1515
"code.gitea.io/gitea/modules/setting"
16-
17-
"github.com/unknwon/com"
1816
)
1917

2018
// LocalCopyPath returns the local repository temporary copy path.
@@ -27,11 +25,15 @@ func LocalCopyPath() string {
2725

2826
// CreateTemporaryPath creates a temporary path
2927
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+
3537
}
3638
return basePath, nil
3739
}

0 commit comments

Comments
 (0)