-
Notifications
You must be signed in to change notification settings - Fork 19
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
transfer: add naive objects transfer function #64
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import TYPE_CHECKING, Set | ||
|
||
if TYPE_CHECKING: | ||
from .db import ObjectDB | ||
|
||
|
||
def transfer( | ||
src: "ObjectDB", dest: "ObjectDB", oids: Set["str"], jobs: int = None | ||
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's a question of how See iterative/dvc#7874. |
||
) -> Set["str"]: | ||
src_exists = set(src.oids_exist(oids, jobs=jobs)) | ||
src_missing = oids - src_exists | ||
|
||
dest_exists = set(dest.oids_exist(oids, jobs=jobs)) | ||
dest_missing = oids - dest_exists | ||
|
||
missing = dest_missing & src_missing | ||
new = src_exists - dest_exists | ||
|
||
for oid in new: | ||
path = src.oid_to_path(oid) | ||
dest.add(path, src.fs, oid) | ||
Comment on lines
+19
to
+21
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. Will add batching support, as soon as |
||
|
||
if missing: | ||
raise Exception("missing objects", missing) | ||
return new |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from dvc_objects.db import ObjectDB | ||
from dvc_objects.transfer import transfer | ||
|
||
|
||
def test_transfer(memfs): | ||
src = ObjectDB(memfs, "/odb1") | ||
dest = ObjectDB(memfs, "/odb2") | ||
|
||
src.add_bytes("1234", b"content") | ||
assert transfer(src, dest, {"1234"}) == {"1234"} | ||
assert dest.exists("1234") |
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.
I'm thinking about whether we even need this function. Based on how we calculate status on
dvc-data
side, the logic here will not be reusable there. Although, this will be useful for the naive transfer of objects.