From dbf754dc846f21d3474431572e6dc338b1b6de67 Mon Sep 17 00:00:00 2001 From: beierlm Date: Wed, 25 May 2022 14:11:11 -0400 Subject: [PATCH] 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 --- osm_nbi/descriptor_topics.py | 5 +++++ 1 file changed, 5 insertions(+) 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): """ -- 2.25.1