From 9e242843628a7d79a679cc142bac58caeab76dbc Mon Sep 17 00:00:00 2001 From: Andrew Thornton <art27@cantab.net> Date: Mon, 9 Dec 2019 17:41:23 +0000 Subject: [PATCH] Use ioutil.TempDir --- models/helper_directory.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/models/helper_directory.go b/models/helper_directory.go index 813f0577bca02..1e239a487fb69 100644 --- a/models/helper_directory.go +++ b/models/helper_directory.go @@ -6,15 +6,13 @@ package models import ( "fmt" + "io/ioutil" "os" "path" "path/filepath" - "time" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - - "github.com/unknwon/com" ) // LocalCopyPath returns the local repository temporary copy path. @@ -27,11 +25,15 @@ func LocalCopyPath() string { // CreateTemporaryPath creates a temporary path func CreateTemporaryPath(prefix string) (string, error) { - timeStr := com.ToStr(time.Now().Nanosecond()) // SHOULD USE SOMETHING UNIQUE - basePath := path.Join(LocalCopyPath(), prefix+"-"+timeStr+".git") - if err := os.MkdirAll(filepath.Dir(basePath), os.ModePerm); err != nil { - log.Error("Unable to create temporary directory: %s (%v)", basePath, err) - return "", fmt.Errorf("Failed to create dir %s: %v", basePath, err) + if err := os.MkdirAll(LocalCopyPath(), os.ModePerm); err != nil { + log.Error("Unable to create localcopypath directory: %s (%v)", LocalCopyPath(), err) + return "", fmt.Errorf("Failed to create localcopypath directory %s: %v", LocalCopyPath(), err) + } + basePath, err := ioutil.TempDir(LocalCopyPath(), prefix+"-*.git") + if err != nil { + log.Error("Unable to create temporary directory: %s-*.git (%v)", prefix, err) + return "", fmt.Errorf("Failed to create dir %s-*.git: %v", prefix, err) + } return basePath, nil }