diff --git a/sources/org.osbuild.curl b/sources/org.osbuild.curl index 842d080c..a39a5303 100755 --- a/sources/org.osbuild.curl +++ b/sources/org.osbuild.curl @@ -24,6 +24,8 @@ import sys import tempfile import time +from typing import Dict + SCHEMA = """ "additionalProperties": false, @@ -214,57 +216,23 @@ def download(checksums, urls, cache): return 0 -def export(checksums, cache, output): - for checksum in checksums: - try: - subprocess.run( - [ - "cp", - "--reflink=auto", - f"{cache}/{checksum}", - f"{output}/{checksum}", - ], - check=True, - ) - except subprocess.CalledProcessError as e: - json.dump({"error": e.output}, sys.stdout) - return 1 +def main(urls: Dict, cache: str): + cache = os.path.join(cache, "org.osbuild.files") + + if not urls: + json.dump({}, sys.stdout) + return 0 + + os.makedirs(cache, exist_ok=True) + res = download(urls.keys(), urls, cache) + if res != 0: + return res json.dump({}, sys.stdout) return 0 -def main(urls, options, checksums, cache, output): - cache = os.path.join(cache, "org.osbuild.files") - download_only = not output - - if not urls: - urls = options.get("urls", []) - - if urls: - if not checksums and download_only: - checksums = [k for k, _ in urls.items()] - - os.makedirs(cache, exist_ok=True) - res = download(checksums, urls, cache) - if res != 0: - return res - - if download_only: - json.dump({}, sys.stdout) - return 0 - - os.makedirs(output, exist_ok=True) - res = export(checksums, cache, output) - - return res - - if __name__ == '__main__': args = json.load(sys.stdin) - r = main(args["items"], - args["options"], - args["checksums"], - args["cache"], - args.get("output")) + r = main(args["items"], args["cache"]) sys.exit(r)