Skip to content

Commit 85d5fc6

Browse files
committed
Remove sub temporary path configurations with a fixed sub path
1 parent d6f6d77 commit 85d5fc6

File tree

10 files changed

+28
-75
lines changed

10 files changed

+28
-75
lines changed

cmd/dump.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var CmdDump = &cli.Command{
4848
&cli.StringFlag{
4949
Name: "tempdir",
5050
Aliases: []string{"t"},
51-
Value: setting.TempPath,
51+
Value: filepath.Join(setting.TempPath, "dump"),
5252
Usage: "Temporary dir path",
5353
},
5454
&cli.StringFlag{
@@ -194,8 +194,8 @@ func runDump(ctx *cli.Context) error {
194194
log.Info("Skipping database")
195195
} else {
196196
tmpDir := ctx.String("tempdir")
197-
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
198-
fatal("Path does not exist: %s", tmpDir)
197+
if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
198+
fatal("Unable to create temporary directory: %s (%v)", tmpDir, err)
199199
}
200200

201201
dbDump, err := os.CreateTemp(tmpDir, "gitea-db.sql")

custom/conf/app.example.ini

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ RUN_USER = ; git
201201
;; relative paths are made absolute relative to the APP_DATA_PATH
202202
;SSH_SERVER_HOST_KEYS=ssh/gitea.rsa, ssh/gogs.rsa
203203
;;
204-
;; Directory to create temporary files in when testing public keys using ssh-keygen,
205-
;; default is the system temporary directory.
206-
;SSH_KEY_TEST_PATH =
207-
;;
208204
;; Use `ssh-keygen` to parse public SSH keys. The value is passed to the shell. By default, Gitea does the parsing itself.
209205
;SSH_KEYGEN_PATH =
210206
;;
@@ -1073,15 +1069,6 @@ LEVEL = Info
10731069
;; Separate extensions with a comma. To line wrap files without an extension, just put a comma
10741070
;LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,.livemd,
10751071

1076-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1077-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1078-
;[repository.local]
1079-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1080-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1081-
;;
1082-
;; Path for local repository copy. Defaults to TEMP_PATH + `local-repo`
1083-
;LOCAL_COPY_PATH = local-repo
1084-
10851072
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10861073
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10871074
;[repository.upload]
@@ -1091,9 +1078,6 @@ LEVEL = Info
10911078
;; Whether repository file uploads are enabled. Defaults to `true`
10921079
;ENABLED = true
10931080
;;
1094-
;; Path for uploads. Defaults to TEMP_PATH + `uploads`
1095-
;TEMP_PATH = uploads
1096-
;;
10971081
;; Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
10981082
;ALLOWED_TYPES =
10991083
;;
@@ -2592,9 +2576,6 @@ LEVEL = Info
25922576
;; Currently, only `minio` and `azureblob` is supported.
25932577
;SERVE_DIRECT = false
25942578
;;
2595-
;; Path for chunked uploads. Defaults it's `package-upload` under `TEMP_PATH` unless it's an absolute path.
2596-
;CHUNKED_UPLOAD_PATH = package-upload
2597-
;;
25982579
;; Maximum count of package versions a single owner can have (`-1` means no limits)
25992580
;LIMIT_TOTAL_OWNER_COUNT = -1
26002581
;; Maximum size of packages a single owner can use (`-1` means no limits, format `1000`, `1 MB`, `1 GiB`)

models/asymkey/ssh_key_parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) {
262262
// writeTmpKeyFile writes key content to a temporary file
263263
// and returns the name of that file, along with any possible errors.
264264
func writeTmpKeyFile(content string) (string, error) {
265-
tmpFile, err := os.CreateTemp(setting.SSH.KeyTestPath, "gitea_keytest")
265+
tmpFile, err := os.CreateTemp(setting.GetSSHKeyTestPath(), "gitea_keytest")
266266
if err != nil {
267267
return "", fmt.Errorf("TempFile: %w", err)
268268
}

models/repo/upload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func init() {
5353

5454
// UploadLocalPath returns where uploads is stored in local file system based on given UUID.
5555
func UploadLocalPath(uuid string) string {
56-
return filepath.Join(setting.Repository.Upload.TempPath, uuid[0:1], uuid[1:2], uuid)
56+
return filepath.Join(setting.GetRepositoryUploadTempPath(), uuid[0:1], uuid[1:2], uuid)
5757
}
5858

5959
// LocalPath returns where uploads are temporarily stored in local file system.

modules/repository/temp.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ import (
1616

1717
// localCopyPath returns the local repository temporary copy path.
1818
func localCopyPath() string {
19-
if setting.Repository.Local.LocalCopyPath == "" {
20-
return filepath.Join(setting.TempPath, "local-repo")
21-
} else if !filepath.IsAbs(setting.Repository.Local.LocalCopyPath) {
22-
return filepath.Join(setting.TempPath, setting.Repository.Local.LocalCopyPath)
23-
}
24-
return setting.Repository.Local.LocalCopyPath
19+
return filepath.Join(setting.TempPath, "local-repo")
2520
}
2621

2722
// CreateTemporaryPath creates a temporary path

modules/setting/packages.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ import (
1515
// Package registry settings
1616
var (
1717
Packages = struct {
18-
Storage *Storage
19-
Enabled bool
20-
ChunkedUploadPath string
18+
Storage *Storage
19+
Enabled bool
2120

2221
LimitTotalOwnerCount int64
2322
LimitTotalOwnerSize int64
@@ -51,6 +50,10 @@ var (
5150
}
5251
)
5352

53+
func GetPacakgeUploadTempPath() string {
54+
return filepath.Join(TempPath, "package-upload")
55+
}
56+
5457
func loadPackagesFrom(rootCfg ConfigProvider) (err error) {
5558
sec, _ := rootCfg.GetSection("packages")
5659
if sec == nil {
@@ -67,14 +70,9 @@ func loadPackagesFrom(rootCfg ConfigProvider) (err error) {
6770
return err
6871
}
6972

70-
Packages.ChunkedUploadPath = filepath.ToSlash(sec.Key("CHUNKED_UPLOAD_PATH").MustString("package-upload"))
71-
if !filepath.IsAbs(Packages.ChunkedUploadPath) {
72-
Packages.ChunkedUploadPath = filepath.Join(TempPath, Packages.ChunkedUploadPath)
73-
}
74-
7573
if HasInstallLock(rootCfg) {
76-
if err := os.MkdirAll(Packages.ChunkedUploadPath, os.ModePerm); err != nil {
77-
return fmt.Errorf("unable to create chunked upload directory: %s (%v)", Packages.ChunkedUploadPath, err)
74+
if err := os.MkdirAll(GetPacakgeUploadTempPath(), os.ModePerm); err != nil {
75+
return fmt.Errorf("unable to create chunked upload directory: %s (%v)", GetPacakgeUploadTempPath(), err)
7876
}
7977
}
8078

modules/setting/repository.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,11 @@ var (
6262
// Repository upload settings
6363
Upload struct {
6464
Enabled bool
65-
TempPath string
6665
AllowedTypes string
6766
FileMaxSize int64
6867
MaxFiles int
6968
} `ini:"-"`
7069

71-
// Repository local settings
72-
Local struct {
73-
LocalCopyPath string
74-
} `ini:"-"`
75-
7670
// Pull request settings
7771
PullRequest struct {
7872
WorkInProgressPrefixes []string
@@ -181,25 +175,16 @@ var (
181175
// Repository upload settings
182176
Upload: struct {
183177
Enabled bool
184-
TempPath string
185178
AllowedTypes string
186179
FileMaxSize int64
187180
MaxFiles int
188181
}{
189182
Enabled: true,
190-
TempPath: "uploads",
191183
AllowedTypes: "",
192184
FileMaxSize: 50,
193185
MaxFiles: 5,
194186
},
195187

196-
// Repository local settings
197-
Local: struct {
198-
LocalCopyPath string
199-
}{
200-
LocalCopyPath: "local-repo",
201-
},
202-
203188
// Pull request settings
204189
PullRequest: struct {
205190
WorkInProgressPrefixes []string
@@ -308,8 +293,6 @@ func loadRepositoryFrom(rootCfg ConfigProvider) {
308293
log.Fatal("Failed to map Repository.Editor settings: %v", err)
309294
} else if err = rootCfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
310295
log.Fatal("Failed to map Repository.Upload settings: %v", err)
311-
} else if err = rootCfg.Section("repository.local").MapTo(&Repository.Local); err != nil {
312-
log.Fatal("Failed to map Repository.Local settings: %v", err)
313296
} else if err = rootCfg.Section("repository.pull-request").MapTo(&Repository.PullRequest); err != nil {
314297
log.Fatal("Failed to map Repository.PullRequest settings: %v", err)
315298
}
@@ -361,13 +344,11 @@ func loadRepositoryFrom(rootCfg ConfigProvider) {
361344
}
362345
}
363346

364-
if Repository.Upload.TempPath == "" {
365-
Repository.Upload.TempPath = filepath.Join(TempPath, "uploads")
366-
} else if !filepath.IsAbs(Repository.Upload.TempPath) {
367-
Repository.Upload.TempPath = filepath.Join(TempPath, Repository.Upload.TempPath)
368-
}
369-
370347
if err := loadRepoArchiveFrom(rootCfg); err != nil {
371348
log.Fatal("loadRepoArchiveFrom: %v", err)
372349
}
373350
}
351+
352+
func GetRepositoryUploadTempPath() string {
353+
return filepath.Join(TempPath, "uploads")
354+
}

modules/setting/ssh.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package setting
55

66
import (
7-
"os"
87
"path/filepath"
98
"strings"
109
"text/template"
@@ -31,7 +30,6 @@ var SSH = struct {
3130
ServerKeyExchanges []string `ini:"SSH_SERVER_KEY_EXCHANGES"`
3231
ServerMACs []string `ini:"SSH_SERVER_MACS"`
3332
ServerHostKeys []string `ini:"SSH_SERVER_HOST_KEYS"`
34-
KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
3533
KeygenPath string `ini:"SSH_KEYGEN_PATH"`
3634
AuthorizedKeysBackup bool `ini:"SSH_AUTHORIZED_KEYS_BACKUP"`
3735
AuthorizedPrincipalsBackup bool `ini:"SSH_AUTHORIZED_PRINCIPALS_BACKUP"`
@@ -61,7 +59,6 @@ var SSH = struct {
6159
MinimumKeySizeCheck: true,
6260
MinimumKeySizes: map[string]int{"ed25519": 256, "ed25519-sk": 256, "ecdsa": 256, "ecdsa-sk": 256, "rsa": 3071},
6361
ServerHostKeys: []string{"ssh/gitea.rsa", "ssh/gogs.rsa"},
64-
KeyTestPath: "ssh_key_test",
6562
AuthorizedKeysCommandTemplate: "{{.AppPath}} --config={{.CustomConf}} serv key-{{.Key.ID}}",
6663
PerWriteTimeout: PerWriteTimeout,
6764
PerWritePerKbTimeout: PerWritePerKbTimeout,
@@ -99,6 +96,10 @@ func parseAuthorizedPrincipalsAllow(values []string) ([]string, bool) {
9996
return authorizedPrincipalsAllow, true
10097
}
10198

99+
func GetSSHKeyTestPath() string {
100+
return filepath.Join(TempPath, "ssh_key_test")
101+
}
102+
102103
func loadSSHFrom(rootCfg ConfigProvider) {
103104
sec := rootCfg.Section("server")
104105
if len(SSH.Domain) == 0 {
@@ -133,14 +134,6 @@ func loadSSHFrom(rootCfg ConfigProvider) {
133134
}
134135
}
135136

136-
SSH.KeyTestPath = sec.Key("SSH_KEY_TEST_PATH").MustString("ssh_key_test")
137-
if !filepath.IsAbs(SSH.KeyTestPath) {
138-
SSH.KeyTestPath = filepath.Join(TempPath, SSH.KeyTestPath)
139-
}
140-
if err := os.MkdirAll(SSH.KeyTestPath, os.ModePerm); err != nil {
141-
log.Fatal("failed to create directory %q for ssh key test: %w", SSH.KeyTestPath, err)
142-
}
143-
144137
SSH.KeygenPath = sec.Key("SSH_KEYGEN_PATH").String()
145138
SSH.Port = sec.Key("SSH_PORT").MustInt(22)
146139
SSH.ListenPort = sec.Key("SSH_LISTEN_PORT").MustInt(SSH.Port)

modules/ssh/init.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func Init() error {
3232

3333
builtinUnused()
3434

35+
// FIXME: why 0o644 for a directory .....
36+
if err := os.MkdirAll(setting.GetSSHKeyTestPath(), 0o644); err != nil {
37+
return fmt.Errorf("failed to create directory %q for ssh key test: %w", setting.GetSSHKeyTestPath(), err)
38+
}
39+
3540
if len(setting.SSH.TrustedUserCAKeys) > 0 && setting.SSH.AuthorizedPrincipalsEnabled {
3641
caKeysFileName := setting.SSH.TrustedUserCAKeysFile
3742
caKeysFileDir := filepath.Dir(caKeysFileName)

services/packages/container/blob_uploader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type BlobUploader struct {
3131
}
3232

3333
func buildFilePath(id string) string {
34-
return util.FilePathJoinAbs(setting.Packages.ChunkedUploadPath, id)
34+
return util.FilePathJoinAbs(setting.GetPacakgeUploadTempPath(), id)
3535
}
3636

3737
// NewBlobUploader creates a new blob uploader for the given id

0 commit comments

Comments
 (0)