mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-27 07:18:28 +01:00
objects: use separate staging ODB for staging trees (#6195)
* fs: use fsspecwrapper in memfs * odb: add memfs staging ODB in ODBManager * odb: add read_only attribute for odb instances * objects: handle memfs paths when staging trees * odb: remove git ODB * output: use staging ODB * RepoDependency: use staging odb for imports * dvcfs: handle case where dir cache is unavailable * fix circular import check * odb: use temp local ODB for staging * objects: use staging ODB in stage() and tree load * objects: add typing for add/check/load/stage * output/dep: use new staging * add unit tests for local odb staging * localfs: account for string paths in move() * include local in odb.by_scheme * tests: count dir cache like any other object in test_pull_git_imports * odb: clear staging on gc() * objects: add tree.get/filter/insert * output: use obj.filter/get for granular dir commit * squash filter logic output * dependency: don't filter imports at the dep level * don't init staging ODB for external cache * use staging ODB when computing tree hash for external outs * remove unneeded force in test granular commit * use unique-per-manager memfs URLs for staging * odb: make staging per-ODBManager * objects: move state dependent staging into ODBManager * objects: support checking multiple odbs - staging dependent checks can be done via ODBManager.check * checkout: do state lookup before explicit stage() in _changed() * output: use odbmanager based staging * RepoDependency: use odbmanager based staging * update obj staging unit tests * checkout: remove check(), handle individual file exceptions on link() * diff: use odbmanager based staging * objects: add ObjectPermissionError for read/write perm errors * odb: move staging out of odbmanager * objects: handle staging ODB in objects.stage() * objects.tree: don't stage anything in tree methods * odb: clear staged objects on gc() * remote: don't filter objs by scheme, objs are already grouped by ODB * diff: update objects.stage usage * output/dep: update stage() usage * update ODB tests * update func tests * remove memfs from FS_MAP * revert unneeded objects.check() changes * remove unused tree.insert() * revert unused odbmanager changes * add separate odb error classes * stage external outs directly in ODB * check for obj existence in main ODB before staging * use .dvc/tmp/staging instead of per-odb staging * gc: only gc loal staging once
This commit is contained in:
@@ -92,3 +92,69 @@ def test_set_exec_ignore_errors(tmp_dir, dvc, mocker, err):
|
||||
)
|
||||
dvc.odb.local.set_exec(PathInfo("foo"))
|
||||
assert mock_chmod.called
|
||||
|
||||
|
||||
def test_staging_file(tmp_dir, dvc):
|
||||
from dvc.objects import check, save
|
||||
from dvc.objects.stage import get_staging, stage
|
||||
|
||||
tmp_dir.gen("foo", "foo")
|
||||
fs = LocalFileSystem()
|
||||
|
||||
local_odb = dvc.odb.local
|
||||
staging_odb = get_staging(local_odb)
|
||||
obj = stage(local_odb, tmp_dir / "foo", fs, "md5")
|
||||
|
||||
for odb in (local_odb, staging_odb):
|
||||
path_info = odb.hash_to_path_info(obj.hash_info.value)
|
||||
assert not odb.fs.exists(path_info)
|
||||
|
||||
# check for file after staging should fail since files are not added on
|
||||
# stage()
|
||||
with pytest.raises(FileNotFoundError):
|
||||
check(local_odb, obj)
|
||||
with pytest.raises(FileNotFoundError):
|
||||
check(staging_odb, obj)
|
||||
|
||||
save(local_odb, obj)
|
||||
check(local_odb, obj)
|
||||
with pytest.raises(FileNotFoundError):
|
||||
check(staging_odb, obj)
|
||||
|
||||
path_info = local_odb.hash_to_path_info(obj.hash_info.value)
|
||||
assert fs.exists(path_info)
|
||||
|
||||
|
||||
def test_staging_dir(tmp_dir, dvc):
|
||||
from dvc.objects import check, save
|
||||
from dvc.objects.stage import get_staging, stage
|
||||
|
||||
tmp_dir.gen({"dir": {"foo": "foo", "bar": "bar"}})
|
||||
fs = LocalFileSystem()
|
||||
local_odb = dvc.odb.local
|
||||
staging_odb = get_staging(local_odb)
|
||||
|
||||
obj = stage(local_odb, tmp_dir / "dir", fs, "md5")
|
||||
|
||||
path_info = local_odb.hash_to_path_info(obj.hash_info.value)
|
||||
assert not local_odb.fs.exists(path_info)
|
||||
path_info = staging_odb.hash_to_path_info(obj.hash_info.value)
|
||||
assert staging_odb.fs.exists(path_info)
|
||||
|
||||
# check for raw object after staging should pass only when using the
|
||||
# staging odb
|
||||
raw = HashFile(obj.path_info, obj.fs, obj.hash_info)
|
||||
with pytest.raises(FileNotFoundError):
|
||||
check(local_odb, raw)
|
||||
check(staging_odb, raw)
|
||||
|
||||
# checking the entire tree should fail since individual file entries are
|
||||
# not added on stage()
|
||||
with pytest.raises(FileNotFoundError):
|
||||
check(staging_odb, obj)
|
||||
|
||||
save(local_odb, obj)
|
||||
check(local_odb, obj)
|
||||
|
||||
path_info = local_odb.hash_to_path_info(obj.hash_info.value)
|
||||
assert fs.exists(path_info)
|
||||
|
||||
Reference in New Issue
Block a user