mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
Replace files only after successful update
This commit is contained in:
parent
dc670252fd
commit
3f34d2a270
@ -180,6 +180,7 @@ def clone_images():
|
|||||||
has_hash_fail = False
|
has_hash_fail = False
|
||||||
|
|
||||||
keep_files = { '.last-url', '.released-time' }
|
keep_files = { '.last-url', '.released-time' }
|
||||||
|
rename_files = []
|
||||||
|
|
||||||
logging.info(f' - Downloading new files')
|
logging.info(f' - Downloading new files')
|
||||||
|
|
||||||
@ -197,19 +198,29 @@ def clone_images():
|
|||||||
|
|
||||||
for mirror_file_name, upstream_file_name, file_hash in image_files:
|
for mirror_file_name, upstream_file_name, file_hash in image_files:
|
||||||
keep_files.add(mirror_file_name)
|
keep_files.add(mirror_file_name)
|
||||||
|
|
||||||
logging.info(f' - {upstream_file_name} -> {mirror_file_name}')
|
logging.info(f' - {upstream_file_name} -> {mirror_file_name}')
|
||||||
download(f'{chan_location}/{upstream_file_name}', chan_path / mirror_file_name)
|
tmp_dest = f'.update.{upstream_file_name}'
|
||||||
actual_hash = file_sha256(chan_path / mirror_file_name)
|
rename_files.append((tmp_dest, mirror_file_name))
|
||||||
|
|
||||||
|
download(f'{chan_location}/{upstream_file_name}', chan_path / tmp_dest)
|
||||||
|
actual_hash = file_sha256(chan_path / tmp_dest)
|
||||||
|
|
||||||
if file_hash != actual_hash:
|
if file_hash != actual_hash:
|
||||||
has_hash_fail = True
|
has_hash_fail = True
|
||||||
|
|
||||||
logging.error(f' - Incorrect hash')
|
logging.error(f' - Incorrect hash')
|
||||||
logging.error(f' actual {actual_hash}')
|
logging.error(f' actual {actual_hash}')
|
||||||
logging.error(f' expected {file_sha256}')
|
logging.error(f' expected {file_hash}')
|
||||||
|
logging.info(f' - File saved as {tmp_dest}')
|
||||||
|
|
||||||
logging.info(f' - Removing old files')
|
if has_hash_fail:
|
||||||
|
logging.warn(f' - Found bad files. Will retry next time.')
|
||||||
|
else:
|
||||||
|
logging.info(f' - Renaming files')
|
||||||
|
|
||||||
|
for tmp_dest, mirror_file_name in rename_files:
|
||||||
|
(chan_path / tmp_dest).rename(chan_path / mirror_file_name)
|
||||||
|
|
||||||
|
logging.info(f' - Removing useless files')
|
||||||
|
|
||||||
for file_path in chan_path.iterdir():
|
for file_path in chan_path.iterdir():
|
||||||
file_name = file_path.name
|
file_name = file_path.name
|
||||||
@ -224,9 +235,6 @@ def clone_images():
|
|||||||
for mirror_file_name, _upstream_file_name, file_hash in image_files:
|
for mirror_file_name, _upstream_file_name, file_hash in image_files:
|
||||||
f.write(f'{file_hash} *{mirror_file_name}\n')
|
f.write(f'{file_hash} *{mirror_file_name}\n')
|
||||||
|
|
||||||
if has_hash_fail:
|
|
||||||
logging.warn(f' - Found bad files. Not marking update as finished')
|
|
||||||
else:
|
|
||||||
logging.info(f' - Update finished')
|
logging.info(f' - Update finished')
|
||||||
atomic_write_file(chan_path / '.last-url', chan_location)
|
atomic_write_file(chan_path / '.last-url', chan_location)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user