Skip to content

Commit cb4b50a

Browse files
committed
Move temporary repo to use the standard temporary path
1 parent 1434bf7 commit cb4b50a

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

modules/repofiles/temp_repo.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ import (
1111
"io"
1212
"os"
1313
"os/exec"
14-
"path"
1514
"regexp"
1615
"strings"
1716
"time"
1817

1918
"code.gitea.io/gitea/models"
2019
"code.gitea.io/gitea/modules/git"
20+
"code.gitea.io/gitea/modules/log"
2121
"code.gitea.io/gitea/modules/process"
2222
"code.gitea.io/gitea/modules/setting"
23-
24-
"github.com/Unknwon/com"
2523
)
2624

2725
// TemporaryUploadRepository is a type to wrap our upload repositories as a shallow clone
@@ -33,22 +31,18 @@ type TemporaryUploadRepository struct {
3331

3432
// NewTemporaryUploadRepository creates a new temporary upload repository
3533
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
4337
}
4438
t := &TemporaryUploadRepository{repo: repo, basePath: basePath}
4539
return t, nil
4640
}
4741

4842
// Close the repository cleaning up all files
4943
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)
5246
}
5347
}
5448

0 commit comments

Comments
 (0)