Skip to content

Commit

Permalink
transfer: add naive transfer function
Browse files Browse the repository at this point in the history
This implements a very naive transfer mechanism without
batching (which should be a straightforward change after
we have batching in odb.add itself).
  • Loading branch information
skshetry authored and efiop committed Jun 22, 2022
1 parent 488c15f commit 4f0cf3c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/dvc_objects/transfer.py
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
) -> 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)

if missing:
raise Exception("missing objects", missing)
return new
11 changes: 11 additions & 0 deletions tests/test_transfer.py
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")

0 comments on commit 4f0cf3c

Please sign in to comment.