[elbe-devel] [PATCH] elbepack: repodir: make preprocessed file cleanup more robust
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Fri Jan 24 10:49:49 CET 2025
The preprocessed file is not valid after Repodir() has exited, so clean
it up automatically. Also gracefully handle the case if an error occurs
before the file was created.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/initvmaction.py | 2 --
elbepack/repodir.py | 8 ++++++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index c427e2adff3f2a45f97798b6c8c777d782efaa98..8f2c750b0fe105e283cb44c74ce48bf4573dc603 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -98,8 +98,6 @@ def _submit_with_repodir_and_dl_result(control, xmlfile, cdrom, args):
_submit_and_dl_result(control, preprocess_xmlfile, cdrom, args)
except RepodirError as err:
raise with_cli_details(err, 127, 'elbe repodir failed')
- finally:
- os.remove(preprocess_xmlfile)
def _submit_and_dl_result(control, xmlfile, cdrom, args):
diff --git a/elbepack/repodir.py b/elbepack/repodir.py
index ce317b80620ef07190d52de4f2d232af80a89c1b..09beb8bf6836094b7d0e947780ca110400cb4eb5 100644
--- a/elbepack/repodir.py
+++ b/elbepack/repodir.py
@@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2022 Linutronix GmbH
+import contextlib
import functools
import os
import sys
@@ -96,11 +97,18 @@ class Repodir:
return self
except XMLSyntaxError:
+ self._remove_output()
raise RepodirError(f'XML Parse error\n{sys.exc_info()[1]}')
except BaseException:
+ self._remove_output()
raise RepodirError(
f'Unknown Exception during validation\n{str(sys.exc_info()[1])}')
def __exit__(self, _typ, _value, _traceback):
+ self._remove_output()
for httpd in self.httpds:
httpd.shutdown()
+
+ def _remove_output(self):
+ with contextlib.suppress(FileNotFoundError):
+ os.remove(self.output)
---
base-commit: 2fd301beadb3b4c7e7318bdd9a41ea582ce3bf29
change-id: 20250124-excursion-symlink-77e9ac0d05ba
Best regards,
--
Thomas Weißschuh <thomas.weissschuh at linutronix.de>
More information about the elbe-devel
mailing list