From c2b79783f556991459aa4350ee451ed9252c087f Mon Sep 17 00:00:00 2001 From: vinoyang Date: Thu, 19 Sep 2024 16:39:12 +0800 Subject: [PATCH] Performance: Reduce call exists in makedirs (#86) --- tosfs/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tosfs/core.py b/tosfs/core.py index 6a54c0a..4e7c06a 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -499,9 +499,10 @@ def makedirs(self, path: str, exist_ok: bool = False) -> None: """ path = self._strip_protocol(path).rstrip("/") + "/" - if exist_ok and self.exists(path): + path_exist = self.exists(path) + if exist_ok and path_exist: return - if not exist_ok and self.exists(path): + if not exist_ok and path_exist: raise FileExistsError(path) self.mkdir(path, create_parents=True)