1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-20 13:50:12 +01: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 os
import logging import logging
import io import io
import tempfile
import shutil
from . import _ from . import _
from . import common from . import common
@ -89,10 +91,12 @@ def main():
newbuilds.append(new) newbuilds.append(new)
app.builds = newbuilds app.builds = newbuilds
try: # rewrite to temporary file before overwriting existsing
metadata.write_metadata(path, app) # file in case there's a bug in write_metadata
finally: with tempfile.TemporaryDirectory() as tmpdir:
pass tmp_path = os.path.join(tmpdir, os.path.basename(path))
metadata.write_metadata(tmp_path, app)
shutil.move(tmp_path, path)
logging.debug(_("Finished")) logging.debug(_("Finished"))