refactor: adopt PathRegistry in worker snapshot_store.go
Update internal/worker/snapshot_store.go to use centralized PathRegistry: Changes: - Add import for internal/config package - Update ResolveSnapshot to use config.FromEnv() for directory creation - Replace os.MkdirAll with paths.EnsureDir() for tmpRoot - Replace os.MkdirAll with paths.EnsureDir() for extractDir - Replace os.MkdirAll with paths.EnsureDir() for cacheDir parent Benefits: - Consistent directory creation via PathRegistry - Centralized path management for snapshot storage - Better error handling for directory creation
This commit is contained in:
parent
a5059c5231
commit
33b893a71a
1 changed files with 6 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/jfraeys/fetch_ml/internal/config"
|
||||
"github.com/jfraeys/fetch_ml/internal/container"
|
||||
"github.com/jfraeys/fetch_ml/internal/fileutil"
|
||||
"github.com/jfraeys/fetch_ml/internal/worker/integrity"
|
||||
|
|
@ -139,7 +140,9 @@ func ResolveSnapshot(
|
|||
defer func() { _ = rc.Close() }()
|
||||
|
||||
tmpRoot := filepath.Join(dataDir, "snapshots", ".tmp")
|
||||
if err := os.MkdirAll(tmpRoot, 0750); err != nil {
|
||||
// Use PathRegistry for consistent directory creation
|
||||
paths := config.FromEnv()
|
||||
if err := paths.EnsureDir(tmpRoot); err != nil {
|
||||
return "", err
|
||||
}
|
||||
workDir, err := os.MkdirTemp(tmpRoot, "fetchml-snapshot-")
|
||||
|
|
@ -163,7 +166,7 @@ func ResolveSnapshot(
|
|||
}
|
||||
|
||||
extractDir := filepath.Join(workDir, "extracted")
|
||||
if err := os.MkdirAll(extractDir, 0750); err != nil {
|
||||
if err := paths.EnsureDir(extractDir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := extractTarGz(archivePath, extractDir); err != nil {
|
||||
|
|
@ -178,7 +181,7 @@ func ResolveSnapshot(
|
|||
return "", fmt.Errorf("snapshot checksum mismatch: expected %s, got %s", want, got)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(cacheDir), 0750); err != nil {
|
||||
if err := paths.EnsureDir(filepath.Dir(cacheDir)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := os.Rename(extractDir, cacheDir); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue