From: beierlm Date: Wed, 25 May 2022 18:11:11 +0000 (-0400) Subject: Bug 2033 NBI leaves files orphaned in fsmongo X-Git-Tag: v10.1.1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=7050aca31b058241ddfb2203c1f0e072168b4961;p=osm%2FNBI.git Bug 2033 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 2033 Change-Id: I4513747c10e469a01a1cef8b89986eb4b6ad59ae Signed-off-by: beierlm --- diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index 8efde1e..1930254 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -241,6 +241,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 = ( @@ -267,6 +268,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 @@ -385,6 +387,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) @@ -416,6 +419,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): """