Skip to content

Commit

Permalink
sources/containers-storage: call exists() when fetch()ing
Browse files Browse the repository at this point in the history
Implement fetch_all() and fetch_one() as calls to exists() to make sure
we check that the containers are available every time they are needed.
  • Loading branch information
achilleas-k authored and ondrejbudai committed Feb 21, 2024
1 parent 45510ae commit ac45c29
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sources/org.osbuild.containers-storage
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ by osbuild itself.
Buildhost commands used: `skopeo`.
"""

import concurrent.futures
import hashlib
import subprocess as sp
import sys
Expand Down Expand Up @@ -57,10 +58,19 @@ class ContainersStorageSource(sources.SourceService):
return f"containers-storage:[{driver}@{graphroot}+{runroot}]{imagename}"

def fetch_one(self, checksum, desc) -> None:
return
# Instead of fetching anything, just check that it exists.
#
# Note that there's an obvious TOCTOU issue here, but it's unavoidable without copying the storage or a
# container out of it, which is exactly what we want to avoid with this source.
# Unlike all other sources, this source relies on external storage not controlled by osbuild itself.
self.exists(checksum, desc)

def fetch_all(self, items) -> None:
return
# prepare each item as a (checksum, desc) tuple (where desc=None)
transformed = map(lambda i: self.transform(i, None), items)
with concurrent.futures.ThreadPoolExecutor(max_workers=self.max_workers) as executor:
for _ in executor.map(self.fetch_one, *zip(*transformed)):
pass

def exists(self, checksum, _) -> bool:
image_id = checksum.split(":")[1]
Expand Down

0 comments on commit ac45c29

Please sign in to comment.