X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_common%2Ffsmongo.py;h=07d4821e942e0df0eb85bbbfb01e4a98b47e5043;hb=refs%2Fchanges%2F75%2F8875%2F4;hp=6a96d4478b14602cf55a3941823d59eea39835d7;hpb=8ab6cc621e77323982e19eaf4f4e1d8ddcd356df;p=osm%2Fcommon.git diff --git a/osm_common/fsmongo.py b/osm_common/fsmongo.py index 6a96d44..07d4821 100644 --- a/osm_common/fsmongo.py +++ b/osm_common/fsmongo.py @@ -195,15 +195,19 @@ class FsMongo(FsBase): self.client = None self.fs = None - def __update_local_fs(self): + def __update_local_fs(self, from_path=None): dir_cursor = self.fs.find({"metadata.type": "dir"}, no_cursor_timeout=True) 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) file_cursor = self.fs.find({"metadata.type": {"$in": ["file", "sym"]}}, no_cursor_timeout=True) for writing_file in file_cursor: + if from_path and not writing_file.filename.startswith(from_path): + continue file_path = self.path + writing_file.filename if writing_file.metadata["type"] == "sym": @@ -452,8 +456,10 @@ class FsMongo(FsBase): except IOError as e: raise FsException("File {} cannot be deleted: {}".format(f, e), http_code=HTTPStatus.INTERNAL_SERVER_ERROR) - def sync(self): + def sync(self, from_path=None): """ Sync from FSMongo to local storage + :param from_path: if supplied, only copy content from this path, not all + :return: None """ - self.__update_local_fs() + self.__update_local_fs(from_path=from_path)