From f7931c34dc1f046c01ce65517a1e6a35417b72a9 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 20 Feb 2023 10:58:16 +0200 Subject: [PATCH] localfs: get_file: use exc-based dir handling Just to avoid wasting stat calls on every file we are copying. --- src/dvc_objects/fs/local.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dvc_objects/fs/local.py b/src/dvc_objects/fs/local.py index 2c4b884..5eb458c 100644 --- a/src/dvc_objects/fs/local.py +++ b/src/dvc_objects/fs/local.py @@ -97,12 +97,14 @@ def put_file(self, lpath, rpath, callback=None, **kwargs): os.replace(tmp_file, rpath) def get_file(self, rpath, lpath, callback=None, **kwargs): - if self.isdir(rpath): - # emulating fsspec's localfs.get_file - self.makedirs(lpath, exist_ok=True) - return - - copyfile(rpath, lpath, callback=callback) + try: + copyfile(rpath, lpath, callback=callback) + except IsADirectoryError: + if self.isdir(rpath): + # emulating fsspec's localfs.get_file + self.makedirs(lpath, exist_ok=True) + else: + raise def mv(self, path1, path2, **kwargs): self.makedirs(self._parent(path2), exist_ok=True)