From: beierlm Date: Wed, 25 May 2022 18:11:11 +0000 (-0400) Subject: Bug 2032 NBI leaves files orphaned in fsmongo X-Git-Tag: v11.0.3 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=c265b67c4a5a7e6b5dc35f2a9370be4ebe1cfaa2;p=osm%2FNBI.git Bug 2032 NBI leaves files orphaned in fsmongo If any form of error occurs when uploading a package, including uploading a package that already exists, the NBI will leave the unpacked descriptor's files in fsmongo. This change tracks fsmongo changes and rolls them back on error. Fixes Bug 20332 Change-Id: I4513747c10e469a01a1cef8b89986eb4b6ad59ae Signed-off-by: beierlm --- diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index deae786..60317aa 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -248,6 +248,7 @@ class DescriptorTopic(BaseTopic): # TODO change to Content-Disposition filename https://tools.ietf.org/html/rfc6266 file_pkg = None error_text = "" + fs_rollback = [] try: if content_range_text: content_range = ( @@ -274,6 +275,7 @@ class DescriptorTopic(BaseTopic): else: self.fs.file_delete(temp_folder, ignore_non_exist=True) self.fs.mkdir(temp_folder) + fs_rollback.append(temp_folder) storage = self.fs.get_params() storage["folder"] = _id @@ -433,6 +435,7 @@ class DescriptorTopic(BaseTopic): current_desc["_admin"]["modified"] = time() self.db.replace(self.topic, _id, current_desc) self.fs.dir_rename(temp_folder, _id) + fs_rollback = [] indata["_id"] = _id self._send_msg("edited", indata) @@ -464,6 +467,8 @@ class DescriptorTopic(BaseTopic): finally: if file_pkg: file_pkg.close() + for file in fs_rollback: + self.fs.file_delete(file, ignore_non_exist=True) def get_file(self, session, _id, path=None, accept_header=None): """