From 08b821e74764652efd7904666af5f7c0715b7c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Schoentgen?= Date: Fri, 15 Jan 2021 17:00:42 +0100 Subject: [PATCH] Special build to log more details in Local.get_children_info() Also using `os.scandir()` to improve performances. I tested `Path.glob("*")` and the old `Path.iterdir()`: `os.scandir()` is a clear winner. --- nxdrive/client/local/base.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/nxdrive/client/local/base.py b/nxdrive/client/local/base.py index f6b3d26b1..3ea508cc7 100644 --- a/nxdrive/client/local/base.py +++ b/nxdrive/client/local/base.py @@ -342,25 +342,23 @@ def is_ignored(self, parent_ref: Path, file_name: str, /) -> bool: return result def _get_children_info(self, ref: Path, /) -> List[FileInfo]: - os_path = self.abspath(ref) + full_path = self.abspath(ref) + paths = [(entry.path, entry.name) for entry in os.scandir(full_path)] result = [] - for child in sorted(os_path.iterdir()): - if self.is_ignored(ref, child.name) or self.is_temp_file(child): - log.info(f"Ignoring banned file {child.name!r} in {os_path!r}") + for path, name in sorted(paths): + if self.is_ignored(ref, name) or self.is_temp_file(Path(path)): + log.info(f"Ignoring banned file {name!r} in {full_path!r}") continue - child_ref = ref / child.name + child_ref = ref / name try: - info = self.get_info(child_ref) + result.append(self.get_info(child_ref)) except NotFound: log.warning( - "The child file has been deleted in the mean time" - " or while reading some of its attributes" + f"The child file {child_ref!r} has been deleted in the" + " mean time or while reading some of its attributes" ) - continue - if info: - result.append(info) return result