From 3fa0668f8984d8a426eda36affbe87888f459cf1 Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Wed, 26 Jan 2022 15:58:26 +0200 Subject: [PATCH] ngclient: simplify storing a downloaded file Replace the usage of securesystemslib.util.persist_temp_file() with shutil.copyfileobj() as file system abstraction is not used in the client. This way we prevent securesystemslib.exception.StorageError from leaking through client API calls. Note: with those changes we are no longer do fsync. Signed-off-by: Martin Vrachev --- tuf/ngclient/updater.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tuf/ngclient/updater.py b/tuf/ngclient/updater.py index 08153dce22..f5cbd89b2c 100644 --- a/tuf/ngclient/updater.py +++ b/tuf/ngclient/updater.py @@ -35,12 +35,11 @@ import logging import os +import shutil import tempfile from typing import Optional, Set from urllib import parse -from securesystemslib import util as sslib_util - from tuf.api import exceptions from tuf.api.metadata import ( Metadata, @@ -218,8 +217,7 @@ def download_target( ValueError: Invalid arguments DownloadError: Download of the target file failed in some way RepositoryError: Downloaded target failed to be verified in some way - exceptions.StorageError: Downloaded target could not be written - to disk + OSError: Failed to write target to file Returns: Local path to downloaded file @@ -252,7 +250,9 @@ def download_target( ) as target_file: targetinfo.verify_length_and_hashes(target_file) - sslib_util.persist_temp_file(target_file, filepath) + target_file.seek(0) + with open(filepath, "wb") as destination_file: + shutil.copyfileobj(target_file, destination_file) logger.info("Downloaded target %s", targetinfo.path) return filepath