Files
zeekay 7844a60aff refactor(pack): modernize to github.com/hanzoai/pack and remove upstream branding
- Migrate module path to github.com/hanzoai/pack across all Go packages
- Remove legacy upstream docs and competitor brand references
- Modernize LLM.md and mise.toml for pristine Hanzo Pack builder
2026-09-04 00:40:42 -07:00

67 lines
1.5 KiB
Go

package generate
import (
"strings"
"github.com/hanzoai/pack/core/plan"
)
const (
APT_CACHE_KEY = "apt"
MISE_CACHE_KEY = "mise"
)
type CacheContext struct {
Caches map[string]*plan.Cache
}
func NewCacheContext() *CacheContext {
return &CacheContext{
Caches: make(map[string]*plan.Cache),
}
}
func (c *CacheContext) AddCache(name string, directory string) string {
return c.AddCacheWithType(name, directory, plan.CacheTypeShared)
}
func (c *CacheContext) AddCacheWithType(name string, directory string, cacheType string) string {
sanitizedName := sanitizeCacheName(name)
c.Caches[sanitizedName] = plan.NewCache(directory)
c.Caches[sanitizedName].Type = cacheType
return sanitizedName
}
func (c *CacheContext) SetCache(name string, cache *plan.Cache) {
c.Caches[name] = cache
}
func (c *CacheContext) GetCache(name string) *plan.Cache {
return c.Caches[name]
}
func (c *CacheContext) GetAptCaches() []string {
if _, ok := c.Caches[APT_CACHE_KEY]; !ok {
aptCache := plan.NewCache("/var/cache/apt")
aptCache.Type = plan.CacheTypeLocked
c.Caches[APT_CACHE_KEY] = aptCache
}
aptListsKey := "apt-lists"
if _, ok := c.Caches[aptListsKey]; !ok {
aptListsCache := plan.NewCache("/var/lib/apt/lists")
aptListsCache.Type = plan.CacheTypeLocked
c.Caches[aptListsKey] = aptListsCache
}
return []string{APT_CACHE_KEY, aptListsKey}
}
func sanitizeCacheName(name string) string {
if len(name) > 0 && name[0] == '/' {
name = name[1:]
}
name = strings.TrimRight(name, "/")
return strings.ReplaceAll(name, "/", "-")
}