mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
6 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
3 years ago
|
package repository
|
||
6 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"path"
|
||
|
"path/filepath"
|
||
|
|
||
|
"code.gitea.io/gitea/modules/log"
|
||
|
"code.gitea.io/gitea/modules/setting"
|
||
4 years ago
|
"code.gitea.io/gitea/modules/util"
|
||
6 years ago
|
)
|
||
|
|
||
|
// LocalCopyPath returns the local repository temporary copy path.
|
||
|
func LocalCopyPath() string {
|
||
|
if filepath.IsAbs(setting.Repository.Local.LocalCopyPath) {
|
||
|
return setting.Repository.Local.LocalCopyPath
|
||
|
}
|
||
|
return path.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath)
|
||
|
}
|
||
|
|
||
|
// CreateTemporaryPath creates a temporary path
|
||
|
func CreateTemporaryPath(prefix string) (string, error) {
|
||
5 years ago
|
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)
|
||
|
}
|
||
3 years ago
|
basePath, err := os.MkdirTemp(LocalCopyPath(), prefix+".git")
|
||
5 years ago
|
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)
|
||
|
|
||
6 years ago
|
}
|
||
|
return basePath, nil
|
||
|
}
|
||
|
|
||
|
// RemoveTemporaryPath removes the temporary path
|
||
|
func RemoveTemporaryPath(basePath string) error {
|
||
|
if _, err := os.Stat(basePath); !os.IsNotExist(err) {
|
||
4 years ago
|
return util.RemoveAll(basePath)
|
||
6 years ago
|
}
|
||
|
return nil
|
||
|
}
|