Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions cmd/limactl/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,20 @@ func knownLocations(ctx context.Context) (map[string]limatype.File, error) {

func locationsFromLimaYAML(y *limatype.LimaYAML) map[string]limatype.File {
locations := make(map[string]limatype.File)
// decompress=false and decompress=true are cached separately
// because the same URL may be used for both compressed and uncompressed files.
for _, decompress := range []bool{false, true} {
for _, f := range y.Images {
locations[downloader.CacheKey(f.Location, decompress)] = f.File
if f.Kernel != nil {
locations[downloader.CacheKey(f.Kernel.Location, decompress)] = f.Kernel.File
}
if f.Initrd != nil {
locations[downloader.CacheKey(f.Initrd.Location, decompress)] = *f.Initrd
}
}
for _, f := range y.Containerd.Archives {
locations[downloader.CacheKey(f.Location, decompress)] = f
for _, f := range y.Images {
locations[downloader.CacheKey(f.Location)] = f.File
if f.Kernel != nil {
locations[downloader.CacheKey(f.Kernel.Location)] = f.Kernel.File
}
for _, f := range y.Firmware.Images {
locations[downloader.CacheKey(f.Location, decompress)] = f.File
if f.Initrd != nil {
locations[downloader.CacheKey(f.Initrd.Location)] = *f.Initrd
}
}
for _, f := range y.Containerd.Archives {
locations[downloader.CacheKey(f.Location)] = f
}
for _, f := range y.Firmware.Images {
locations[downloader.CacheKey(f.Location)] = f.File
}
return locations
}
20 changes: 8 additions & 12 deletions pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func Download(ctx context.Context, local, remote string, opts ...Opt) (*Result,
return res, nil
}

shad := cacheDirectoryPath(o.cacheDir, remote, o.decompress)
shad := cacheDirectoryPath(o.cacheDir, remote)
if err := os.MkdirAll(shad, 0o700); err != nil {
return nil, err
}
Expand All @@ -255,7 +255,7 @@ func Download(ctx context.Context, local, remote string, opts ...Opt) (*Result,
// nil if the file was copied, nil, nil if the file is not in the cache or the
// cache needs update, or nil, error on fatal error.
func getCached(ctx context.Context, localPath, remote string, o options) (*Result, error) {
shad := cacheDirectoryPath(o.cacheDir, remote, o.decompress)
shad := cacheDirectoryPath(o.cacheDir, remote)
shadData := filepath.Join(shad, "data")
shadTime := filepath.Join(shad, "time")
shadType := filepath.Join(shad, "type")
Expand Down Expand Up @@ -301,7 +301,7 @@ func getCached(ctx context.Context, localPath, remote string, o options) (*Resul

// fetch downloads remote to the cache and copy the cached file to local path.
func fetch(ctx context.Context, localPath, remote string, o options) (*Result, error) {
shad := cacheDirectoryPath(o.cacheDir, remote, o.decompress)
shad := cacheDirectoryPath(o.cacheDir, remote)
shadData := filepath.Join(shad, "data")
shadTime := filepath.Join(shad, "time")
shadType := filepath.Join(shad, "type")
Expand Down Expand Up @@ -354,7 +354,7 @@ func Cached(remote string, opts ...Opt) (*Result, error) {
return nil, errors.New("local files are not cached")
}

shad := cacheDirectoryPath(o.cacheDir, remote, o.decompress)
shad := cacheDirectoryPath(o.cacheDir, remote)
shadData := filepath.Join(shad, "data")
shadTime := filepath.Join(shad, "time")
shadType := filepath.Join(shad, "type")
Expand Down Expand Up @@ -404,8 +404,8 @@ func Cached(remote string, opts ...Opt) (*Result, error) {
// - "data" file contains the data
// - "time" file contains the time (Last-Modified header)
// - "type" file contains the type (Content-Type header)
func cacheDirectoryPath(cacheDir, remote string, decompress bool) string {
return filepath.Join(cacheDir, "download", "by-url-sha256", CacheKey(remote, decompress))
func cacheDirectoryPath(cacheDir, remote string) string {
return filepath.Join(cacheDir, "download", "by-url-sha256", CacheKey(remote))
}

// cacheDigestPath returns the cache digest file path.
Expand Down Expand Up @@ -775,12 +775,8 @@ func CacheEntries(opts ...Opt) (map[string]string, error) {
}

// CacheKey returns the key for a cache entry of the remote URL.
func CacheKey(remote string, decompress bool) string {
k := fmt.Sprintf("%x", sha256.Sum256([]byte(remote)))
if decompress && decompressor(remote) != "" {
k += "+decomp"
}
return k
func CacheKey(remote string) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(remote)))
}

// RemoveAllCacheDir removes the cache directory.
Expand Down