diff --git a/osbuild/sources.py b/osbuild/sources.py index 956e841d..20235095 100644 --- a/osbuild/sources.py +++ b/osbuild/sources.py @@ -54,6 +54,10 @@ class SourceService(host.Service): def download(self, items, cache, options): pass + def setup(self, cache, content_type): + self.cache = os.path.join(cache, content_type) + os.makedirs(self.cache, exist_ok=True) + def dispatch(self, method: str, args, fds): if method == "download": with os.fdopen(fds.steal(0)) as f: diff --git a/sources/org.osbuild.curl b/sources/org.osbuild.curl index d46cd6a0..a0953bfa 100755 --- a/sources/org.osbuild.curl +++ b/sources/org.osbuild.curl @@ -166,10 +166,8 @@ def download(items, cache): class CurlSource(sources.SourceService): def download(self, items, cache, _options): - cache = os.path.join(cache, "org.osbuild.files") - os.makedirs(cache, exist_ok=True) - - download(items, cache) + self.setup(cache, "org.osbuild.files") + download(items, self.cache) def main(): diff --git a/sources/org.osbuild.inline b/sources/org.osbuild.inline index 74206793..a2c45c2f 100755 --- a/sources/org.osbuild.inline +++ b/sources/org.osbuild.inline @@ -82,11 +82,9 @@ def process(items: Dict, cache: str, tmpdir): class InlineSource(sources.SourceService): def download(self, items, cache, _options): - cache = os.path.join(cache, "org.osbuild.files") - os.makedirs(cache, exist_ok=True) - + self.setup(cache, "org.osbuild.files") with tempfile.TemporaryDirectory(prefix=".unverified-", dir=cache) as tmpdir: - process(items, cache, tmpdir) + process(items, self.cache, tmpdir) def main(): diff --git a/sources/org.osbuild.ostree b/sources/org.osbuild.ostree index 07ec4938..836ff6a1 100755 --- a/sources/org.osbuild.ostree +++ b/sources/org.osbuild.ostree @@ -115,10 +115,9 @@ def download(items, cache): class OSTreeSource(sources.SourceService): def download(self, items, cache, _options): - cache = os.path.join(cache, "org.osbuild.ostree") - os.makedirs(cache, exist_ok=True) + self.setup(cache, "org.osbuild.ostree") - download(items, cache) + download(items, self.cache) def main(): diff --git a/sources/org.osbuild.skopeo b/sources/org.osbuild.skopeo index c9f7b230..1146b0a6 100755 --- a/sources/org.osbuild.skopeo +++ b/sources/org.osbuild.skopeo @@ -119,10 +119,9 @@ def download(items, cache): class SkopeoSource(sources.SourceService): def download(self, items, cache, _options): - cache = os.path.join(cache, "org.osbuild.containers") - os.makedirs(cache, exist_ok=True) + self.setup(cache, "org.osbuild.containers") - download(items, cache) + download(items, self.cache) def main():