aboutsummaryrefslogtreecommitdiff
path: root/internal/conf
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-02-22 15:22:32 +0800
committerGitHub <noreply@github.com>2020-02-22 15:22:32 +0800
commitc4a0a404735cdcfdcb805e9fed474c75110bca89 (patch)
treed4ef0af7722425451f23b6ca06ef90a375a5f6bc /internal/conf
parentf59a68c531c680d4488d8d977798f6aa36551bfa (diff)
conf: overhaul repository settings (#5932)
Diffstat (limited to 'internal/conf')
-rw-r--r--internal/conf/conf.go77
-rw-r--r--internal/conf/static.go41
-rw-r--r--internal/conf/utils.go9
3 files changed, 63 insertions, 64 deletions
diff --git a/internal/conf/conf.go b/internal/conf/conf.go
index ac8e2877..63df2c8e 100644
--- a/internal/conf/conf.go
+++ b/internal/conf/conf.go
@@ -100,6 +100,7 @@ func Init(customConf string) error {
if err = File.Section("server").MapTo(&Server); err != nil {
return errors.Wrap(err, "mapping [server] section")
}
+ Server.AppDataPath = ensureAbs(Server.AppDataPath)
if !strings.HasSuffix(Server.ExternalURL, "/") {
Server.ExternalURL += "/"
@@ -122,22 +123,19 @@ func Init(customConf string) error {
}
Server.UnixSocketMode = os.FileMode(unixSocketMode)
- if !filepath.IsAbs(Server.AppDataPath) {
- Server.AppDataPath = filepath.Join(WorkDir(), Server.AppDataPath)
- }
-
// ************************
// ----- SSH settings -----
// ************************
+ SSH.RootPath = filepath.Join(HomeDir(), ".ssh")
+ SSH.KeyTestPath = os.TempDir()
if err = File.Section("server").MapTo(&SSH); err != nil {
return errors.Wrap(err, "mapping SSH settings from [server] section")
}
+ SSH.RootPath = ensureAbs(SSH.RootPath)
+ SSH.KeyTestPath = ensureAbs(SSH.KeyTestPath)
if !SSH.Disabled {
- SSH.RootPath = filepath.Join(HomeDir(), ".ssh")
- SSH.KeyTestPath = os.TempDir()
-
if !SSH.StartBuiltinServer {
if err := os.MkdirAll(SSH.RootPath, 0700); err != nil {
return errors.Wrap(err, "create SSH root directory")
@@ -173,7 +171,18 @@ func Init(customConf string) error {
}
}
- transferDeprecated()
+ // *******************************
+ // ----- Repository settings -----
+ // *******************************
+
+ Repository.Root = filepath.Join(HomeDir(), "gogs-repositories")
+ if err = File.Section("repository").MapTo(&Repository); err != nil {
+ return errors.Wrap(err, "mapping [repository] section")
+ }
+ Repository.Root = ensureAbs(Repository.Root)
+ Repository.Upload.TempPath = ensureAbs(Repository.Upload.TempPath)
+
+ handleDeprecated()
// TODO
@@ -224,27 +233,6 @@ func Init(customConf string) error {
"StampNano": time.StampNano,
}[File.Section("time").Key("FORMAT").MustString("RFC1123")]
- // Determine and create root git repository path.
- sec = File.Section("repository")
- RepoRootPath = sec.Key("ROOT").MustString(filepath.Join(HomeDir(), "gogs-repositories"))
- if !filepath.IsAbs(RepoRootPath) {
- RepoRootPath = path.Join(workDir, RepoRootPath)
- } else {
- RepoRootPath = path.Clean(RepoRootPath)
- }
- ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
- if err = File.Section("repository").MapTo(&Repository); err != nil {
- log.Fatal("Failed to map Repository settings: %v", err)
- } else if err = File.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
- log.Fatal("Failed to map Repository.Editor settings: %v", err)
- } else if err = File.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
- log.Fatal("Failed to map Repository.Upload settings: %v", err)
- }
-
- if !filepath.IsAbs(Repository.Upload.TempPath) {
- Repository.Upload.TempPath = path.Join(workDir, Repository.Upload.TempPath)
- }
-
sec = File.Section("picture")
AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(filepath.Join(Server.AppDataPath, "avatars"))
if !filepath.IsAbs(AvatarUploadPath) {
@@ -361,37 +349,6 @@ var (
UsePostgreSQL bool
UseMSSQL bool
- // Repository settings
- Repository struct {
- AnsiCharset string
- ForcePrivate bool
- MaxCreationLimit int
- MirrorQueueLength int
- PullRequestQueueLength int
- PreferredLicenses []string
- DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
- EnableLocalPathMigration bool
- CommitsFetchConcurrency int
- EnableRawFileRenderMode bool
-
- // Repository editor settings
- Editor struct {
- LineWrapExtensions []string
- PreviewableFileModes []string
- } `ini:"-"`
-
- // Repository upload settings
- Upload struct {
- Enabled bool
- TempPath string
- AllowedTypes []string `delim:"|"`
- FileMaxSize int64
- MaxFiles int
- } `ini:"-"`
- }
- RepoRootPath string
- ScriptType string
-
// Webhook settings
Webhook struct {
Types []string
diff --git a/internal/conf/static.go b/internal/conf/static.go
index ff9a4f48..c9fff1dc 100644
--- a/internal/conf/static.go
+++ b/internal/conf/static.go
@@ -12,9 +12,13 @@ import (
// ℹ️ README: This file contains static values that should only be set at initialization time.
// HasMinWinSvc is whether the application is built with Windows Service support.
+//
+// ⚠️ WARNING: should only be set by "static_minwinsvc.go".
var HasMinWinSvc bool
-// Build information should only be set by -ldflags.
+// Build time and commit information.
+//
+// ⚠️ WARNING: should only be set by -ldflags.
var (
BuildTime string
BuildCommit string
@@ -28,7 +32,7 @@ var CustomConf string
var (
// Application settings
App struct {
- // ⚠️ WARNING: Should only be set by gogs.go.
+ // ⚠️ WARNING: Should only be set by main package (i.e. "gogs.go").
Version string `ini:"-"`
BrandName string
@@ -90,10 +94,39 @@ var (
ListenPort int `ini:"SSH_LISTEN_PORT"`
ServerCiphers []string `ini:"SSH_SERVER_CIPHERS"`
}
+
+ // Repository settings
+ Repository struct {
+ Root string
+ ScriptType string
+ ANSICharset string `ini:"ANSI_CHARSET"`
+ ForcePrivate bool
+ MaxCreationLimit int
+ PreferredLicenses []string
+ DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
+ EnableLocalPathMigration bool
+ EnableRawFileRenderMode bool
+ CommitsFetchConcurrency int
+
+ // Repository editor settings
+ Editor struct {
+ LineWrapExtensions []string
+ PreviewableFileModes []string
+ } `ini:"repository.editor"`
+
+ // Repository upload settings
+ Upload struct {
+ Enabled bool
+ TempPath string
+ AllowedTypes []string `delim:"|"`
+ FileMaxSize int64
+ MaxFiles int
+ } `ini:"repository.upload"`
+ }
)
-// transferDeprecated transfers deprecated values to the new ones when set.
-func transferDeprecated() {
+// handleDeprecated transfers deprecated values to the new ones when set.
+func handleDeprecated() {
if App.AppName != "" {
App.BrandName = App.AppName
App.AppName = ""
diff --git a/internal/conf/utils.go b/internal/conf/utils.go
index ad716018..5da34f0c 100644
--- a/internal/conf/utils.go
+++ b/internal/conf/utils.go
@@ -5,6 +5,7 @@
package conf
import (
+ "path/filepath"
"strings"
"github.com/pkg/errors"
@@ -25,3 +26,11 @@ func openSSHVersion() (string, error) {
v = strings.TrimSuffix(strings.TrimPrefix(v, "OpenSSH_"), "p")
return v, nil
}
+
+// ensureAbs prepends the WorkDir to the given path if it is not an absolute path.
+func ensureAbs(path string) string {
+ if filepath.IsAbs(path) {
+ return path
+ }
+ return filepath.Join(WorkDir(), path)
+}