Skip to content

Commit 3b519f2

Browse files
authored
fs.get_file: wrap callback when passing to transfer (#596)
1 parent 02739b0 commit 3b519f2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/dvc_data/fs.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, BinaryIO, NamedTuple, Optional
99

1010
from fsspec import AbstractFileSystem
11-
from fsspec.callbacks import DEFAULT_CALLBACK
11+
from fsspec.callbacks import DEFAULT_CALLBACK, NoOpCallback
1212

1313
if typing.TYPE_CHECKING:
1414
from dvc_objects.fs.base import AnyFSPath, FileSystem
@@ -22,6 +22,13 @@
2222
logger = logging.getLogger(__name__)
2323

2424

25+
class _WrappedCallback(NoOpCallback):
26+
# check `_get_file` for more details
27+
def branched(self, path_1, path_2, **kwargs):
28+
# NOTE: only safe for a single use
29+
return self.kw.get("callback", DEFAULT_CALLBACK)
30+
31+
2532
class FileInfo(NamedTuple):
2633
typ: str
2734
storage: "ObjectStorage"
@@ -220,7 +227,12 @@ def get_file(
220227
path,
221228
fs,
222229
os.fspath(lpath),
223-
callback=callback,
230+
# `transfer` supports uploading multiple files, so it uses the
231+
# passed callback to iterate for no. of files.
232+
# So, we wrap the given callback in a `NoOpCallback` and return it
233+
# in `branch` so that file copy callback gets properly called.
234+
# This is safe for transferring a single file.
235+
callback=_WrappedCallback(callback=callback),
224236
links=copy.copy(storage.odb.cache_types),
225237
)
226238
return

0 commit comments

Comments
 (0)