Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngclient: simplify storing a downloaded file #1799

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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