|
8 | 8 | from typing import Any, BinaryIO, NamedTuple, Optional
|
9 | 9 |
|
10 | 10 | from fsspec import AbstractFileSystem
|
11 |
| -from fsspec.callbacks import DEFAULT_CALLBACK |
| 11 | +from fsspec.callbacks import DEFAULT_CALLBACK, NoOpCallback |
12 | 12 |
|
13 | 13 | if typing.TYPE_CHECKING:
|
14 | 14 | from dvc_objects.fs.base import AnyFSPath, FileSystem
|
|
22 | 22 | logger = logging.getLogger(__name__)
|
23 | 23 |
|
24 | 24 |
|
| 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 | + |
25 | 32 | class FileInfo(NamedTuple):
|
26 | 33 | typ: str
|
27 | 34 | storage: "ObjectStorage"
|
@@ -220,7 +227,12 @@ def get_file(
|
220 | 227 | path,
|
221 | 228 | fs,
|
222 | 229 | 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), |
224 | 236 | links=copy.copy(storage.odb.cache_types),
|
225 | 237 | )
|
226 | 238 | return
|
|
0 commit comments