mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
- 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
67 lines
1.5 KiB
Go
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, "/", "-")
|
|
}
|