container: Handle edge cases with container update

Fix update command failing when image files do not exist.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Joseph Nuthalapati 2020-09-27 22:25:09 +05:30 committed by Veiko Aasa
parent 3f4bd9416d
commit 2416d87398
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -286,11 +286,11 @@ def _get_systemd_nspawn_version():
def _download_file(url, target_file, force=False):
"""Download a file from remote URL."""
if target_file.exists() and not force:
return
if force:
os.remove(target_file)
if target_file.exists():
if force:
os.remove(target_file)
else:
return
partial_file = target_file.with_suffix(target_file.suffix + '.partial')
@ -805,8 +805,12 @@ def _get_latest_image_timestamp(distribution):
def _is_update_required(distribution):
"""Compare local image timestamp against the latest image timestamp."""
filename = URLS[distribution].split('/')[-1]
local_image_timestamp = os.path.getmtime(work_directory / filename)
file_path = work_directory / URLS[distribution].split('/')[-1]
if not file_path.exists():
return True
local_image_timestamp = os.path.getmtime(file_path)
one_day = datetime.timedelta(days=1).total_seconds()
latest_image_timestamp = _get_latest_image_timestamp(distribution)
return latest_image_timestamp - local_image_timestamp > one_day