Skip to content

Commit

Permalink
ngclient: simplify storing a downloaded file
Browse files Browse the repository at this point in the history
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 <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Jan 27, 2022
1 parent d95ead6 commit 3fa0668
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tuf/ngclient/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3fa0668

Please sign in to comment.