1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-03 17:50:11 +02:00

rewritemeta: overwrite existing metadata only if no exception occurred

This commit is contained in:
Michael Pöhn 2020-08-19 23:13:23 +02:00
parent c45ef453fd
commit 5c3db9a7cc

View File

@ -21,6 +21,8 @@ from argparse import ArgumentParser
import os
import logging
import io
import tempfile
import shutil
from . import _
from . import common
@ -89,10 +91,12 @@ def main():
newbuilds.append(new)
app.builds = newbuilds
try:
metadata.write_metadata(path, app)
finally:
pass
# rewrite to temporary file before overwriting existsing
# file in case there's a bug in write_metadata
with tempfile.TemporaryDirectory() as tmpdir:
tmp_path = os.path.join(tmpdir, os.path.basename(path))
metadata.write_metadata(tmp_path, app)
shutil.move(tmp_path, path)
logging.debug(_("Finished"))