From: bravof Date: Tue, 23 Nov 2021 13:34:43 +0000 (-0300) Subject: bugfix: fix for folders missing in mongoFS X-Git-Tag: v11.0.0rc2~1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F13%2F11413%2F1;p=osm%2Fcommon.git bugfix: fix for folders missing in mongoFS Change-Id: I9c8a07755457c3c297853bda8e6c5516409a6fde Signed-off-by: bravof (cherry picked from commit f73a900d6ca2e6002efe1533d7188fb52a5ee7fe) --- diff --git a/osm_common/fsmongo.py b/osm_common/fsmongo.py index ff37c42..51dc11f 100644 --- a/osm_common/fsmongo.py +++ b/osm_common/fsmongo.py @@ -203,10 +203,13 @@ class FsMongo(FsBase): def __update_local_fs(self, from_path=None): dir_cursor = self.fs.find({"metadata.type": "dir"}, no_cursor_timeout=True) + valid_paths = [] + for directory in dir_cursor: if from_path and not directory.filename.startswith(from_path): continue os.makedirs(self.path + directory.filename, exist_ok=True) + valid_paths.append(self.path + directory.filename) file_cursor = self.fs.find( {"metadata.type": {"$in": ["file", "sym"]}}, no_cursor_timeout=True @@ -231,6 +234,9 @@ class FsMongo(FsBase): raise os.symlink(link, file_path) else: + folder = os.path.dirname(file_path) + if folder not in valid_paths: + os.makedirs(folder, exist_ok=True) with open(file_path, "wb+") as file_stream: self.fs.download_to_stream(writing_file._id, file_stream) if "permissions" in writing_file.metadata: