2026-07-18 04:55:33 +00:00
|
|
|
package config
|
2026-07-18 00:07:53 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2026-07-18 04:55:33 +00:00
|
|
|
// DefaultChunkPlanRoot resolves the existing per-user chunk-plan cache root.
|
2026-07-18 00:07:53 +00:00
|
|
|
func DefaultChunkPlanRoot(userCacheDir func() (string, error)) (string, error) {
|
2026-07-18 12:42:10 +00:00
|
|
|
return defaultCacheFamilyRoot(userCacheDir, "chunk-plans")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DefaultCheckpointRoot(userCacheDir func() (string, error)) (string, error) {
|
|
|
|
|
return defaultCacheFamilyRoot(userCacheDir, "checkpoints")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func defaultCacheFamilyRoot(userCacheDir func() (string, error), family string) (string, error) {
|
2026-07-18 00:07:53 +00:00
|
|
|
if userCacheDir == nil {
|
|
|
|
|
return "", fmt.Errorf("user cache directory resolver must not be nil")
|
|
|
|
|
}
|
|
|
|
|
root, err := userCacheDir()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("resolve user cache directory: %w", err)
|
|
|
|
|
}
|
|
|
|
|
root = strings.TrimSpace(root)
|
|
|
|
|
if root == "" {
|
|
|
|
|
return "", fmt.Errorf("user cache directory must not be empty")
|
|
|
|
|
}
|
2026-07-18 12:42:10 +00:00
|
|
|
return filepath.Join(filepath.Clean(root), "notarius", family), nil
|
2026-07-18 00:07:53 +00:00
|
|
|
}
|