Skip to content

Commit

Permalink
Fixed cache evicting same-filename entries from different sources
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaudin committed Jan 29, 2024
1 parent a461119 commit 79bcec9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- [cache] `keep_identified_versions` evicting same-filename entries from different sources

## [0.9.2] - 2024-01-26

### Changed
Expand Down
18 changes: 12 additions & 6 deletions src/image_creator/cache/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ def __init__(self, item: Item, added_on: datetime.datetime | None = None):


def get_eviction_for(
entries: list[CacheEntry], policy: Policy | OCIImagePolicy | FilesPolicy
entries: list[CacheEntry],
policy: Policy | OCIImagePolicy | FilesPolicy,
root: pathlib.Path,
) -> list[tuple[CacheEntry, str]]:
"""list of (entry, reason) from entries that are expired or outdated"""
if (
Expand All @@ -224,13 +226,14 @@ def get_eviction_for(

def matched_ident_version(entry: CacheEntry) -> idv | None:
"""ident and version from entry if it was identified as versioned (or None)"""
path_in_cache = entry.fpath.relative_to(root)
if isinstance(policy, OCIImagePolicy):
re_version = RE_OCI_VERSIONED
if isinstance(policy, FilesPolicy):
re_version = RE_FILES_VERSIONED
if isinstance(policy, OCIImagePolicy | FilesPolicy):
version_match = re_version.match( # pyright: ignore [reportUnboundVariable]
entry.fpath.name
str(path_in_cache)
)
if version_match:
return idv(
Expand All @@ -239,13 +242,13 @@ def matched_ident_version(entry: CacheEntry) -> idv | None:
)
return
# we're at main policy
oci_version_match = RE_OCI_VERSIONED.match(entry.fpath.name)
oci_version_match = RE_OCI_VERSIONED.match(str(path_in_cache))
if oci_version_match:
return idv(
oci_version_match.groupdict()["ident"],
oci_version_match.groupdict()["version"],
)
files_version_match = RE_FILES_VERSIONED.match(entry.fpath.name)
files_version_match = RE_FILES_VERSIONED.match(str(path_in_cache))
if files_version_match:
return idv(
files_version_match.groupdict()["ident"],
Expand Down Expand Up @@ -595,6 +598,7 @@ def get_eviction_for(
evictions = get_eviction_for(
[entry for entry in entries if entry.kind == "image"],
self.policy.oci_images,
self.root,
)
else:
evictions = []
Expand All @@ -603,10 +607,12 @@ def get_eviction_for(

if self.policy.files:
evictions += get_eviction_for(
[entry for entry in entries if entry.kind == "file"], self.policy.files
[entry for entry in entries if entry.kind == "file"],
self.policy.files,
self.root,
)
entries = [entry for entry in entries if entry not in evictions]
evictions += get_eviction_for(entries, self.policy)
evictions += get_eviction_for(entries, self.policy, self.root)

return list(set(evictions))

Expand Down

0 comments on commit 79bcec9

Please sign in to comment.