detached fb6535b

feat(config): Enhance logging for data directory handling in configuration

- Add debug logging to Load function for cases where data_dir is empty, using a default value.
- Implement debug logging in getDefaultDataDir to track the detection of the default data directory based on user environment.
- Update NewServer function to log the initialized registry storage path for better traceability.
commit
fb6535b10a517081edea282587db8ba64569a979
author
bamen · · 2025-06-07 09:12 UTC
parent
04ad628
signature
unsigned
2 files · +21 -3
M internal/config/config.go +17 -2
@@ -6,6 +6,7 @@ import (
66 "path/filepath"
77 "strings"
88
9+ "github.com/rs/zerolog/log"
910 "github.com/spf13/viper"
1011 )
1112
@@ -59,6 +60,12 @@ func Load() (*Config, error) {
5960 return nil, fmt.Errorf("unable to decode server config: %v", err)
6061 }
6162
63+ // If data_dir is empty after loading config, use the default
64+ if cfg.Server.DataDir == "" {
65+ cfg.Server.DataDir = defaultDataDir
66+ log.Debug().Str("data_dir", cfg.Server.DataDir).Msg("Config had empty data_dir, using default")
67+ }
68+
6269 // Get registry auth config
6370 if err := viper.UnmarshalKey("registry_auth", &cfg.RegistryAuth); err != nil {
6471 return nil, fmt.Errorf("unable to decode registry auth config: %v", err)
@@ -136,12 +143,20 @@ func (c *Config) GetRoutes() []Route {
136143
137144 // getDefaultDataDir returns a platform-appropriate default data directory
138145 func getDefaultDataDir() string {
146+ uid := os.Getuid()
147+ log.Debug().Int("uid", uid).Msg("Detecting default data directory")
148+
139149 // Check if we're running in a rootless environment
140- if os.Getuid() != 0 {
150+ if uid != 0 {
141151 // For rootless environments, use user's home directory or current directory
142152 if homeDir, err := os.UserHomeDir(); err == nil {
143- return filepath.Join(homeDir, ".local/share/gordon")
153+ dataDir := filepath.Join(homeDir, ".local/share/gordon")
154+ log.Debug().Str("data_dir", dataDir).Msg("Using user data directory for rootless environment")
155+ return dataDir
144156 }
157+ log.Debug().Msg("Failed to get user home directory, falling back to ./data")
158+ } else {
159+ log.Debug().Msg("Running as root, using ./data")
145160 }
146161
147162 // For root or when home directory is not available, use relative path
@@ -6,6 +6,7 @@ import (
6 "path/filepath"6 "path/filepath"
7 "strings"7 "strings"
8 8
9+ "github.com/rs/zerolog/log"
9 "github.com/spf13/viper"10 "github.com/spf13/viper"
10 )11 )
11 12
@@ -59,6 +60,12 @@ func Load() (*Config, error) {
59 return nil, fmt.Errorf("unable to decode server config: %v", err)60 return nil, fmt.Errorf("unable to decode server config: %v", err)
60 }61 }
61 62
63+ // If data_dir is empty after loading config, use the default
64+ if cfg.Server.DataDir == "" {
65+ cfg.Server.DataDir = defaultDataDir
66+ log.Debug().Str("data_dir", cfg.Server.DataDir).Msg("Config had empty data_dir, using default")
67+ }
68+
62 // Get registry auth config69 // Get registry auth config
63 if err := viper.UnmarshalKey("registry_auth", &cfg.RegistryAuth); err != nil {70 if err := viper.UnmarshalKey("registry_auth", &cfg.RegistryAuth); err != nil {
64 return nil, fmt.Errorf("unable to decode registry auth config: %v", err)71 return nil, fmt.Errorf("unable to decode registry auth config: %v", err)
@@ -136,12 +143,20 @@ func (c *Config) GetRoutes() []Route {
136 143
137 // getDefaultDataDir returns a platform-appropriate default data directory144 // getDefaultDataDir returns a platform-appropriate default data directory
138 func getDefaultDataDir() string {145 func getDefaultDataDir() string {
146+ uid := os.Getuid()
147+ log.Debug().Int("uid", uid).Msg("Detecting default data directory")
148+
139 // Check if we're running in a rootless environment149 // Check if we're running in a rootless environment
140- if os.Getuid() != 0 {150+ if uid != 0 {
141 // For rootless environments, use user's home directory or current directory151 // For rootless environments, use user's home directory or current directory
142 if homeDir, err := os.UserHomeDir(); err == nil {152 if homeDir, err := os.UserHomeDir(); err == nil {
143- return filepath.Join(homeDir, ".local/share/gordon")153+ dataDir := filepath.Join(homeDir, ".local/share/gordon")
154+ log.Debug().Str("data_dir", dataDir).Msg("Using user data directory for rootless environment")
155+ return dataDir
144 }156 }
157+ log.Debug().Msg("Failed to get user home directory, falling back to ./data")
158+ } else {
159+ log.Debug().Msg("Running as root, using ./data")
145 }160 }
146 161
147 // For root or when home directory is not available, use relative path162 // For root or when home directory is not available, use relative path
M internal/registry/server.go +4 -1
@@ -24,7 +24,10 @@ type Server struct {
2424
2525 func NewServer(cfg *config.Config, eventBus events.EventBus) (*Server, error) {
2626 // Initialize storage
27- storage, err := NewFilesystemStorage(cfg.Server.DataDir + "/registry")
27+ registryPath := cfg.Server.DataDir + "/registry"
28+ log.Debug().Str("data_dir", cfg.Server.DataDir).Str("registry_path", registryPath).Msg("Initializing registry storage")
29+
30+ storage, err := NewFilesystemStorage(registryPath)
2831 if err != nil {
2932 return nil, fmt.Errorf("failed to initialize storage: %w", err)
3033 }
@@ -24,7 +24,10 @@ type Server struct {
24 24
25 func NewServer(cfg *config.Config, eventBus events.EventBus) (*Server, error) {25 func NewServer(cfg *config.Config, eventBus events.EventBus) (*Server, error) {
26 // Initialize storage26 // Initialize storage
27- storage, err := NewFilesystemStorage(cfg.Server.DataDir + "/registry")27+ registryPath := cfg.Server.DataDir + "/registry"
28+ log.Debug().Str("data_dir", cfg.Server.DataDir).Str("registry_path", registryPath).Msg("Initializing registry storage")
29+
30+ storage, err := NewFilesystemStorage(registryPath)
28 if err != nil {31 if err != nil {
29 return nil, fmt.Errorf("failed to initialize storage: %w", err)32 return nil, fmt.Errorf("failed to initialize storage: %w", err)
30 }33 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close