mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-12 10:48:46 +03:00

This PR uniform all temporary directory usage so that it will be easier to manage. Relate to #31792 - [x] Added a new setting to allow users to configure the global temporary directory. - [x] Move all temporary files and directories to be placed under os.Temp()/gitea. - [x] `setting.Repository.Local.LocalCopyPath` now will be `setting.TempPath/local-repo` and the customized path is removed. ```diff -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;[repository.local] -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; Path for local repository copy. Defaults to TEMP_PATH + `local-repo`, this is deprecated and cannot be changed -;LOCAL_COPY_PATH = local-repo ``` - [x] `setting.Repository.Upload.TempPath` now will be `settting.TempPath/uploads` and the customized path is removed. ```diff ;[repository.upload] -;; -;; Path for uploads. Defaults to TEMP_PATH + `uploads` -;TEMP_PATH = uploads ``` - [x] `setting.Packages.ChunkedUploadPath` now will be `settting.TempPath/package-upload` and the customized path is removed. ```diff ;[packages] -;; -;; Path for chunked uploads. Defaults it's `package-upload` under `TEMP_PATH` unless it's an absolute path. -;CHUNKED_UPLOAD_PATH = package-upload ``` - [x] `setting.SSH.KeyTestPath` now will be `settting.TempPath/ssh_key_test` and the customized path is removed. ```diff [server] -;; -;; Directory to create temporary files in when testing public keys using ssh-keygen, -;; default is the system temporary directory. -;SSH_KEY_TEST_PATH = ``` TODO: - [ ] setting.PprofDataPath haven't been changed because it may need to be kept until somebody read it but temp path may be clean up any time. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
115 lines
3.5 KiB
Go
115 lines
3.5 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package setting
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
|
|
"github.com/dustin/go-humanize"
|
|
)
|
|
|
|
// Package registry settings
|
|
var (
|
|
Packages = struct {
|
|
Storage *Storage
|
|
Enabled bool
|
|
ChunkedUploadPath string
|
|
|
|
LimitTotalOwnerCount int64
|
|
LimitTotalOwnerSize int64
|
|
LimitSizeAlpine int64
|
|
LimitSizeArch int64
|
|
LimitSizeCargo int64
|
|
LimitSizeChef int64
|
|
LimitSizeComposer int64
|
|
LimitSizeConan int64
|
|
LimitSizeConda int64
|
|
LimitSizeContainer int64
|
|
LimitSizeCran int64
|
|
LimitSizeDebian int64
|
|
LimitSizeGeneric int64
|
|
LimitSizeGo int64
|
|
LimitSizeHelm int64
|
|
LimitSizeMaven int64
|
|
LimitSizeNpm int64
|
|
LimitSizeNuGet int64
|
|
LimitSizePub int64
|
|
LimitSizePyPI int64
|
|
LimitSizeRpm int64
|
|
LimitSizeRubyGems int64
|
|
LimitSizeSwift int64
|
|
LimitSizeVagrant int64
|
|
|
|
DefaultRPMSignEnabled bool
|
|
}{
|
|
Enabled: true,
|
|
LimitTotalOwnerCount: -1,
|
|
}
|
|
)
|
|
|
|
func loadPackagesFrom(rootCfg ConfigProvider) (err error) {
|
|
sec, _ := rootCfg.GetSection("packages")
|
|
if sec == nil {
|
|
Packages.Storage, err = getStorage(rootCfg, "packages", "", nil)
|
|
return err
|
|
}
|
|
|
|
if err = sec.MapTo(&Packages); err != nil {
|
|
return fmt.Errorf("failed to map Packages settings: %v", err)
|
|
}
|
|
|
|
Packages.Storage, err = getStorage(rootCfg, "packages", "", sec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if HasInstallLock(rootCfg) {
|
|
Packages.ChunkedUploadPath, err = AppDataTempDir("package-upload").MkdirAllSub("")
|
|
if err != nil {
|
|
return fmt.Errorf("unable to create chunked upload directory: %w", err)
|
|
}
|
|
}
|
|
|
|
Packages.LimitTotalOwnerSize = mustBytes(sec, "LIMIT_TOTAL_OWNER_SIZE")
|
|
Packages.LimitSizeAlpine = mustBytes(sec, "LIMIT_SIZE_ALPINE")
|
|
Packages.LimitSizeArch = mustBytes(sec, "LIMIT_SIZE_ARCH")
|
|
Packages.LimitSizeCargo = mustBytes(sec, "LIMIT_SIZE_CARGO")
|
|
Packages.LimitSizeChef = mustBytes(sec, "LIMIT_SIZE_CHEF")
|
|
Packages.LimitSizeComposer = mustBytes(sec, "LIMIT_SIZE_COMPOSER")
|
|
Packages.LimitSizeConan = mustBytes(sec, "LIMIT_SIZE_CONAN")
|
|
Packages.LimitSizeConda = mustBytes(sec, "LIMIT_SIZE_CONDA")
|
|
Packages.LimitSizeContainer = mustBytes(sec, "LIMIT_SIZE_CONTAINER")
|
|
Packages.LimitSizeCran = mustBytes(sec, "LIMIT_SIZE_CRAN")
|
|
Packages.LimitSizeDebian = mustBytes(sec, "LIMIT_SIZE_DEBIAN")
|
|
Packages.LimitSizeGeneric = mustBytes(sec, "LIMIT_SIZE_GENERIC")
|
|
Packages.LimitSizeGo = mustBytes(sec, "LIMIT_SIZE_GO")
|
|
Packages.LimitSizeHelm = mustBytes(sec, "LIMIT_SIZE_HELM")
|
|
Packages.LimitSizeMaven = mustBytes(sec, "LIMIT_SIZE_MAVEN")
|
|
Packages.LimitSizeNpm = mustBytes(sec, "LIMIT_SIZE_NPM")
|
|
Packages.LimitSizeNuGet = mustBytes(sec, "LIMIT_SIZE_NUGET")
|
|
Packages.LimitSizePub = mustBytes(sec, "LIMIT_SIZE_PUB")
|
|
Packages.LimitSizePyPI = mustBytes(sec, "LIMIT_SIZE_PYPI")
|
|
Packages.LimitSizeRpm = mustBytes(sec, "LIMIT_SIZE_RPM")
|
|
Packages.LimitSizeRubyGems = mustBytes(sec, "LIMIT_SIZE_RUBYGEMS")
|
|
Packages.LimitSizeSwift = mustBytes(sec, "LIMIT_SIZE_SWIFT")
|
|
Packages.LimitSizeVagrant = mustBytes(sec, "LIMIT_SIZE_VAGRANT")
|
|
Packages.DefaultRPMSignEnabled = sec.Key("DEFAULT_RPM_SIGN_ENABLED").MustBool(false)
|
|
return nil
|
|
}
|
|
|
|
func mustBytes(section ConfigSection, key string) int64 {
|
|
const noLimit = "-1"
|
|
|
|
value := section.Key(key).MustString(noLimit)
|
|
if value == noLimit {
|
|
return -1
|
|
}
|
|
bytes, err := humanize.ParseBytes(value)
|
|
if err != nil || bytes > math.MaxInt64 {
|
|
return -1
|
|
}
|
|
return int64(bytes)
|
|
}
|