2019-05-11 16:29:17 +01:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-05-11 16:29:17 +01:00
|
|
|
|
2022-05-09 00:46:32 +08:00
|
|
|
package repository
|
2019-05-11 16:29:17 +01:00
|
|
|
|
|
|
|
|
import (
|
2025-04-08 09:15:28 -07:00
|
|
|
"context"
|
2019-05-11 16:29:17 +01:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// CreateTemporaryPath creates a temporary path
|
2025-04-08 09:15:28 -07:00
|
|
|
func CreateTemporaryPath(prefix string) (string, context.CancelFunc, error) {
|
|
|
|
|
basePath, cleanup, err := setting.AppDataTempDir("local-repo").MkdirTempRandom(prefix + ".git")
|
2019-12-13 22:21:06 +00:00
|
|
|
if err != nil {
|
|
|
|
|
log.Error("Unable to create temporary directory: %s-*.git (%v)", prefix, err)
|
2025-04-08 09:15:28 -07:00
|
|
|
return "", nil, fmt.Errorf("failed to create dir %s-*.git: %w", prefix, err)
|
2019-05-11 16:29:17 +01:00
|
|
|
}
|
2025-04-08 09:15:28 -07:00
|
|
|
return basePath, cleanup, nil
|
2019-05-11 16:29:17 +01:00
|
|
|
}
|