-
Notifications
You must be signed in to change notification settings - Fork 1.2k
migrate use of upload_fobj to use transfer #6558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import io | ||
import logging | ||
import os | ||
from typing import TYPE_CHECKING, Dict | ||
|
||
from dvc.scheme import Schemes | ||
|
@@ -60,25 +58,19 @@ def _add_file( | |
hash_info: "HashInfo", | ||
move: bool = False, | ||
): | ||
from dvc import fs | ||
|
||
self.makedirs(to_info.parent) | ||
if hash_info.isdir: | ||
return super()._add_file( | ||
from_fs, from_info, to_info, hash_info, move | ||
from_fs, from_info, to_info, hash_info, move=move | ||
) | ||
|
||
ref_file = ReferenceHashFile(from_info, from_fs, hash_info) | ||
self._obj_cache[hash_info] = ref_file | ||
ref_fobj = io.BytesIO(ref_file.to_bytes()) | ||
ref_fobj.seek(0) | ||
try: | ||
self.fs.upload_fobj(ref_fobj, to_info) | ||
except OSError as exc: | ||
if isinstance(exc, FileExistsError) or ( | ||
os.name == "nt" | ||
and exc.__context__ | ||
and isinstance(exc.__context__, FileExistsError) | ||
): | ||
logger.debug("'%s' file already exists, skipping", to_info) | ||
else: | ||
raise | ||
content = ref_file.to_bytes() | ||
fs.utils.transfer( | ||
from_fs, from_info, self.fs, to_info, move=move, content=content | ||
) | ||
Comment on lines
+72
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The It seems to me like we should still have a distinction between a file transfer and a direct binary data write/upload, since in this case there really isn't a One alternative would maybe be adding something like (but this seems a bit more convoluted than just having an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, initially I started with two methods, but at the end We do the following when transferring files straight to the remote, which is just a file transfer at the end: with fs.open(path_info, mode="rb", chunk_size=fs.CHUNK_SIZE) as stream:
stream = HashedStreamReader(stream)
upload_odb.fs.upload_fobj(
stream, tmp_info, desc=path_info.name, size=fs.getsize(path_info)
) But maybe the best thing to do here is put that burden on the caller itself, rather than trying to generalize it in |
||
if from_fs.scheme != Schemes.LOCAL: | ||
self._fs_cache[ReferenceHashFile.config_tuple(from_fs)] = from_fs |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit overloaded though, but moving with it for now.