diff --git a/modules/git/repo.go b/modules/git/repo.go index 1c223018ad..027bd56244 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -18,6 +18,7 @@ import ( "time" "code.gitea.io/gitea/modules/proxy" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" ) @@ -279,11 +280,11 @@ func GetDivergingCommits(ctx context.Context, repoPath, baseBranch, targetBranch // CreateBundle create bundle content to the target path func (repo *Repository) CreateBundle(ctx context.Context, commit string, out io.Writer) error { - tmp, err := os.MkdirTemp(os.TempDir(), "gitea-bundle") + tmp, err := os.MkdirTemp(setting.TempDir(), "gitea-bundle") if err != nil { return err } - defer os.RemoveAll(tmp) + defer util.RemoveAll(tmp) env := append(os.Environ(), "GIT_OBJECT_DIRECTORY="+filepath.Join(repo.Path, "objects")) _, _, err = NewCommand(ctx, "init", "--bare").RunStdString(&RunOpts{Dir: tmp, Env: env}) diff --git a/modules/git/repo_index.go b/modules/git/repo_index.go index 0cff4f6db5..da5e786fab 100644 --- a/modules/git/repo_index.go +++ b/modules/git/repo_index.go @@ -11,6 +11,7 @@ import ( "strings" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" ) @@ -51,7 +52,7 @@ func (repo *Repository) readTreeToIndex(id ObjectID, indexFilename ...string) er // ReadTreeToTemporaryIndex reads a treeish to a temporary index file func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename, tmpDir string, cancel context.CancelFunc, err error) { - tmpDir, err = os.MkdirTemp(os.TempDir(), "index") + tmpDir, err = os.MkdirTemp(setting.TempDir(), "index") if err != nil { return filename, tmpDir, cancel, err } diff --git a/modules/repository/temp.go b/modules/repository/temp.go index 4a0ad24876..4299901292 100644 --- a/modules/repository/temp.go +++ b/modules/repository/temp.go @@ -4,6 +4,7 @@ package repository import ( + "context" "fmt" "os" "path/filepath" @@ -16,9 +17,9 @@ import ( // localCopyPath returns the local repository temporary copy path. func localCopyPath() string { if setting.Repository.Local.LocalCopyPath == "" { - return filepath.Join(os.TempDir(), "local-repo") + return filepath.Join(setting.TempDir(), "local-repo") } else if !filepath.IsAbs(setting.Repository.Local.LocalCopyPath) { - return filepath.Join(os.TempDir(), setting.Repository.Local.LocalCopyPath) + return filepath.Join(setting.TempDir(), setting.Repository.Local.LocalCopyPath) } return setting.Repository.Local.LocalCopyPath } @@ -30,7 +31,7 @@ func CleanUpTemporaryPaths() { } // CreateTemporaryPath creates a temporary path -func CreateTemporaryPath(prefix string) (string, func(), error) { +func CreateTemporaryPath(prefix string) (string, context.CancelFunc, error) { if err := os.MkdirAll(localCopyPath(), os.ModePerm); err != nil { log.Error("Unable to create localcopypath directory: %s (%v)", localCopyPath(), err) return "", func() {}, fmt.Errorf("failed to create localcopypath directory %s: %w", localCopyPath(), err)