refactor(dependency-hygiene): Move path functions from config to storage
Move ExpandPath function and path-related utilities from internal/config to internal/storage where they belong. Files updated: - internal/worker/config.go: use storage.ExpandPath - internal/network/ssh.go: use storage.ExpandPath - cmd/data_manager/data_manager_config.go: use storage.ExpandPath - internal/api/server_config.go: use storage.ExpandPath internal/storage/paths.go already contained the canonical implementation. Result: Path utilities now live in storage layer, config package focuses on configuration structs.
This commit is contained in:
parent
dbf96020af
commit
320e6fd409
4 changed files with 16 additions and 13 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/jfraeys/fetch_ml/internal/auth"
|
||||
"github.com/jfraeys/fetch_ml/internal/config"
|
||||
"github.com/jfraeys/fetch_ml/internal/fileutil"
|
||||
"github.com/jfraeys/fetch_ml/internal/storage"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
|
@ -83,8 +84,8 @@ func LoadDataConfig(path string) (*DataConfig, error) {
|
|||
}
|
||||
|
||||
// Expand paths
|
||||
cfg.MLDataDir = config.ExpandPath(cfg.MLDataDir)
|
||||
cfg.NASDataDir = config.ExpandPath(cfg.NASDataDir)
|
||||
cfg.MLDataDir = storage.ExpandPath(cfg.MLDataDir)
|
||||
cfg.NASDataDir = storage.ExpandPath(cfg.NASDataDir)
|
||||
if cfg.MaxAgeHours == 0 {
|
||||
cfg.MaxAgeHours = config.DefaultMaxAgeHours
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/jfraeys/fetch_ml/internal/config"
|
||||
"github.com/jfraeys/fetch_ml/internal/fileutil"
|
||||
"github.com/jfraeys/fetch_ml/internal/logging"
|
||||
"github.com/jfraeys/fetch_ml/internal/storage"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
|
@ -181,7 +182,7 @@ func (c *ServerConfig) Validate() error {
|
|||
if strings.TrimSpace(c.Queue.SQLitePath) == "" {
|
||||
c.Queue.SQLitePath = filepath.Join(c.DataDir, "queue.db")
|
||||
}
|
||||
c.Queue.SQLitePath = config.ExpandPath(c.Queue.SQLitePath)
|
||||
c.Queue.SQLitePath = storage.ExpandPath(c.Queue.SQLitePath)
|
||||
if !filepath.IsAbs(c.Queue.SQLitePath) {
|
||||
c.Queue.SQLitePath = filepath.Join(config.DefaultLocalDataDir, c.Queue.SQLitePath)
|
||||
}
|
||||
|
|
@ -190,7 +191,7 @@ func (c *ServerConfig) Validate() error {
|
|||
if strings.TrimSpace(c.Queue.FilesystemPath) == "" {
|
||||
c.Queue.FilesystemPath = filepath.Join(c.DataDir, "queue-fs")
|
||||
}
|
||||
c.Queue.FilesystemPath = config.ExpandPath(c.Queue.FilesystemPath)
|
||||
c.Queue.FilesystemPath = storage.ExpandPath(c.Queue.FilesystemPath)
|
||||
if !filepath.IsAbs(c.Queue.FilesystemPath) {
|
||||
c.Queue.FilesystemPath = filepath.Join(config.DefaultLocalDataDir, c.Queue.FilesystemPath)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jfraeys/fetch_ml/internal/config"
|
||||
"github.com/jfraeys/fetch_ml/internal/fileutil"
|
||||
"github.com/jfraeys/fetch_ml/internal/storage"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/agent"
|
||||
"golang.org/x/crypto/ssh/knownhosts"
|
||||
|
|
@ -34,7 +34,7 @@ func NewSSHClient(host, user, keyPath string, port int, knownHostsPath string) (
|
|||
return &SSHClient{client: nil, host: ""}, nil
|
||||
}
|
||||
|
||||
keyPath = config.ExpandPath(keyPath)
|
||||
keyPath = storage.ExpandPath(keyPath)
|
||||
if strings.HasPrefix(keyPath, "~") {
|
||||
home, _ := os.UserHomeDir()
|
||||
keyPath = filepath.Join(home, keyPath[1:])
|
||||
|
|
@ -63,7 +63,7 @@ func NewSSHClient(host, user, keyPath string, port int, knownHostsPath string) (
|
|||
//nolint:gosec // G106: Use of InsecureIgnoreHostKey is intentional fallback
|
||||
hostKeyCallback := ssh.InsecureIgnoreHostKey()
|
||||
if knownHostsPath != "" {
|
||||
knownHostsPath = config.ExpandPath(knownHostsPath)
|
||||
knownHostsPath = storage.ExpandPath(knownHostsPath)
|
||||
if _, err := os.Stat(knownHostsPath); err == nil {
|
||||
callback, err := knownhosts.New(knownHostsPath)
|
||||
if err != nil {
|
||||
|
|
@ -110,7 +110,7 @@ func NewSSHClient(host, user, keyPath string, port int, knownHostsPath string) (
|
|||
// NewLocalClient creates a local-mode SSHClient that executes commands on the host.
|
||||
func NewLocalClient(basePath string) *SSHClient {
|
||||
if basePath != "" {
|
||||
basePath = config.ExpandPath(basePath)
|
||||
basePath = storage.ExpandPath(basePath)
|
||||
}
|
||||
|
||||
return &SSHClient{
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/jfraeys/fetch_ml/internal/config"
|
||||
"github.com/jfraeys/fetch_ml/internal/fileutil"
|
||||
"github.com/jfraeys/fetch_ml/internal/queue"
|
||||
"github.com/jfraeys/fetch_ml/internal/storage"
|
||||
"github.com/jfraeys/fetch_ml/internal/tracking/factory"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
|
@ -206,13 +207,13 @@ func LoadConfig(path string) (*Config, error) {
|
|||
if strings.TrimSpace(cfg.Queue.SQLitePath) == "" {
|
||||
cfg.Queue.SQLitePath = filepath.Join(cfg.DataDir, "queue.db")
|
||||
}
|
||||
cfg.Queue.SQLitePath = config.ExpandPath(cfg.Queue.SQLitePath)
|
||||
cfg.Queue.SQLitePath = storage.ExpandPath(cfg.Queue.SQLitePath)
|
||||
}
|
||||
if strings.EqualFold(strings.TrimSpace(cfg.Queue.Backend), string(queue.QueueBackendFS)) || cfg.Queue.FallbackToFilesystem {
|
||||
if strings.TrimSpace(cfg.Queue.FilesystemPath) == "" {
|
||||
cfg.Queue.FilesystemPath = filepath.Join(cfg.DataDir, "queue-fs")
|
||||
}
|
||||
cfg.Queue.FilesystemPath = config.ExpandPath(cfg.Queue.FilesystemPath)
|
||||
cfg.Queue.FilesystemPath = storage.ExpandPath(cfg.Queue.FilesystemPath)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(cfg.GPUVendor) == "" {
|
||||
|
|
@ -254,7 +255,7 @@ func (c *Config) Validate() error {
|
|||
|
||||
if c.BasePath != "" {
|
||||
// Convert relative paths to absolute
|
||||
c.BasePath = config.ExpandPath(c.BasePath)
|
||||
c.BasePath = storage.ExpandPath(c.BasePath)
|
||||
if !filepath.IsAbs(c.BasePath) {
|
||||
// Resolve relative to current working directory, not DefaultBasePath
|
||||
cwd, err := os.Getwd()
|
||||
|
|
@ -278,7 +279,7 @@ func (c *Config) Validate() error {
|
|||
if strings.TrimSpace(c.Queue.SQLitePath) == "" {
|
||||
return fmt.Errorf("queue.sqlite_path is required when queue.backend is %q", queue.QueueBackendSQLite)
|
||||
}
|
||||
c.Queue.SQLitePath = config.ExpandPath(c.Queue.SQLitePath)
|
||||
c.Queue.SQLitePath = storage.ExpandPath(c.Queue.SQLitePath)
|
||||
if !filepath.IsAbs(c.Queue.SQLitePath) {
|
||||
c.Queue.SQLitePath = filepath.Join(config.DefaultLocalDataDir, c.Queue.SQLitePath)
|
||||
}
|
||||
|
|
@ -287,7 +288,7 @@ func (c *Config) Validate() error {
|
|||
if strings.TrimSpace(c.Queue.FilesystemPath) == "" {
|
||||
return fmt.Errorf("queue.filesystem_path is required when filesystem queue is enabled")
|
||||
}
|
||||
c.Queue.FilesystemPath = config.ExpandPath(c.Queue.FilesystemPath)
|
||||
c.Queue.FilesystemPath = storage.ExpandPath(c.Queue.FilesystemPath)
|
||||
if !filepath.IsAbs(c.Queue.FilesystemPath) {
|
||||
c.Queue.FilesystemPath = filepath.Join(config.DefaultLocalDataDir, c.Queue.FilesystemPath)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue