Skip to content

Commit 42bb8a5

Browse files
committed
Move DefaultCachePath to the config pkg
1 parent f035599 commit 42bb8a5

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

internal/cache/cache.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ type CacheStats struct {
3232
Additions int64
3333
}
3434

35-
func DefaultCachePath() string {
36-
home, err := os.UserHomeDir()
37-
if err != nil {
38-
panic("Failed to get user home directory")
39-
}
40-
41-
dir := filepath.Join(home, ".cache", "hashup")
42-
43-
err = os.MkdirAll(dir, 0755)
44-
if err != nil {
45-
panic("Failed to create cache directory")
46-
}
47-
48-
return filepath.Join(dir, "cache")
49-
}
50-
5135
// NewFileCache creates a new file cache with a specified size limit in MB
5236
func NewFileCache(ctx context.Context, sizeMB int, cachePath string) *FileCache {
5337
log.Debugf("Creating or loading file cache with size %dMB at %s", sizeMB, cachePath)

internal/config/config.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strings"
88

99
"github.com/BurntSushi/toml"
10-
"github.com/rubiojr/hashup/internal/cache"
1110
"github.com/urfave/cli/v2"
1211
)
1312

@@ -85,7 +84,7 @@ func DefaultConfig() Config {
8584
Scanner: ScannerConfig{
8685
ScanningInterval: 3600, // 1 hour in seconds
8786
ScanningConcurrency: 5,
88-
CachePath: cache.DefaultCachePath(),
87+
CachePath: DefaultCachePath(),
8988
},
9089
}
9190
}
@@ -247,3 +246,19 @@ func DefaultNATSDataDir() string {
247246
}
248247
return filepath.Join(home, ".local", "share", "hashup", "nats")
249248
}
249+
250+
func DefaultCachePath() string {
251+
home, err := os.UserHomeDir()
252+
if err != nil {
253+
panic("Failed to get user home directory")
254+
}
255+
256+
dir := filepath.Join(home, ".cache", "hashup")
257+
258+
err = os.MkdirAll(dir, 0755)
259+
if err != nil {
260+
panic("Failed to create cache directory")
261+
}
262+
263+
return filepath.Join(dir, "cache")
264+
}

internal/scanner/scanner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"slices"
1010

1111
"github.com/rubiojr/hashup/internal/cache"
12+
"github.com/rubiojr/hashup/internal/config"
1213
"github.com/rubiojr/hashup/internal/log"
1314
"github.com/rubiojr/hashup/internal/pool"
1415
"github.com/rubiojr/hashup/internal/processors"
@@ -96,7 +97,7 @@ func NewDirectoryScanner(rootDir string, options ...Option) *DirectoryScanner {
9697
ignoreHidden: true,
9798
pool: pool.NewPool(5),
9899
// TODO: context propagagion
99-
cache: cache.NewFileCache(context.Background(), 100, cache.DefaultCachePath()),
100+
cache: cache.NewFileCache(context.Background(), 100, config.DefaultCachePath()),
100101
}
101102

102103
// apply options

0 commit comments

Comments
 (0)