Skip to content

Commit

Permalink
Use ioutil.TempDir
Browse files Browse the repository at this point in the history
  • Loading branch information
zeripath committed Dec 9, 2019
1 parent f2f0a41 commit 9e24284
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions models/helper_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down

0 comments on commit 9e24284

Please sign in to comment.