support ~ in rootDir as home directory

This commit is contained in:
André Roth
2024-08-02 17:48:57 +02:00
parent f7f220aa18
commit 32a3943821
4 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error {
// anything else must fail. // anything else must fail.
// E.g.: Running the service under a different user may lead to a rootDir // E.g.: Running the service under a different user may lead to a rootDir
// that exists but is not usable due to access permissions. // that exists but is not usable due to access permissions.
err = utils.DirIsAccessible(context.Config().RootDir) err = utils.DirIsAccessible(context.Config().GetRootDir())
if err != nil { if err != nil {
return err return err
} }
+1 -1
View File
@@ -29,7 +29,7 @@ func aptlyServe(cmd *commander.Command, args []string) error {
// anything else must fail. // anything else must fail.
// E.g.: Running the service under a different user may lead to a rootDir // E.g.: Running the service under a different user may lead to a rootDir
// that exists but is not usable due to access permissions. // that exists but is not usable due to access permissions.
err = utils.DirIsAccessible(context.Config().RootDir) err = utils.DirIsAccessible(context.Config().GetRootDir())
if err != nil { if err != nil {
return err return err
} }
+3 -3
View File
@@ -275,7 +275,7 @@ func (context *AptlyContext) DBPath() string {
// DBPath builds path to database // DBPath builds path to database
func (context *AptlyContext) dbPath() string { func (context *AptlyContext) dbPath() string {
return filepath.Join(context.config().RootDir, "db") return filepath.Join(context.config().GetRootDir(), "db")
} }
// Database opens and returns current instance of database // Database opens and returns current instance of database
@@ -406,7 +406,7 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
publishedStorage, ok := context.publishedStorages[name] publishedStorage, ok := context.publishedStorages[name]
if !ok { if !ok {
if name == "" { if name == "" {
publishedStorage = files.NewPublishedStorage(filepath.Join(context.config().RootDir, "public"), "hardlink", "") publishedStorage = files.NewPublishedStorage(filepath.Join(context.config().GetRootDir(), "public"), "hardlink", "")
} else if strings.HasPrefix(name, "filesystem:") { } else if strings.HasPrefix(name, "filesystem:") {
params, ok := context.config().FileSystemPublishRoots[name[11:]] params, ok := context.config().FileSystemPublishRoots[name[11:]]
if !ok { if !ok {
@@ -464,7 +464,7 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
// UploadPath builds path to upload storage // UploadPath builds path to upload storage
func (context *AptlyContext) UploadPath() string { func (context *AptlyContext) UploadPath() string {
return filepath.Join(context.Config().RootDir, "upload") return filepath.Join(context.Config().GetRootDir(), "upload")
} }
func (context *AptlyContext) pgpProvider() string { func (context *AptlyContext) pgpProvider() string {
+6
View File
@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings"
) )
// ConfigStructure is structure of main configuration // ConfigStructure is structure of main configuration
@@ -209,3 +210,8 @@ func SaveConfig(filename string, config *ConfigStructure) error {
_, err = f.Write(encoded) _, err = f.Write(encoded)
return err return err
} }
// GetRootDir returns the RootDir with expanded ~ as home directory
func (conf *ConfigStructure) GetRootDir() string {
return strings.Replace(conf.RootDir, "~", os.Getenv("HOME"), 1)
}