mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-01 09:30:29 +00:00
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:
parent
3f4bd9416d
commit
2416d87398
18
container
18
container
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user