dvc: refactor cache saving (#5314)

This commit is contained in:
Ruslan Kuprieiev
2021-01-22 19:07:36 +02:00
committed by GitHub
parent 7b59108379
commit cbd7472079
14 changed files with 145 additions and 182 deletions
+31 -9
View File
@@ -194,26 +194,48 @@ def test_default_cache_type(dvc):
@pytest.mark.skipif(os.name == "nt", reason="Not supported for Windows.")
@pytest.mark.parametrize(
"group, dir_mode", [(False, 0o755), (True, 0o775)],
"group", [False, True],
)
def test_shared_cache(tmp_dir, dvc, group, dir_mode):
def test_shared_cache(tmp_dir, dvc, group):
from dvc.utils.fs import umask
if group:
with dvc.config.edit() as conf:
conf["cache"].update({"shared": "group"})
dvc.cache = Cache(dvc)
cache_dir = dvc.cache.local.cache_dir
assert not os.path.exists(cache_dir)
tmp_dir.dvc_gen(
{"file": "file content", "dir": {"file2": "file 2 " "content"}}
)
for root, dnames, fnames in os.walk(dvc.cache.local.cache_dir):
for dname in dnames:
path = os.path.join(root, dname)
assert stat.S_IMODE(os.stat(path).st_mode) == dir_mode
actual = {}
for root, dnames, fnames in os.walk(cache_dir):
for name in dnames + fnames:
path = os.path.join(root, name)
actual[path] = oct(stat.S_IMODE(os.stat(path).st_mode))
for fname in fnames:
path = os.path.join(root, fname)
assert stat.S_IMODE(os.stat(path).st_mode) == 0o444
file_mode = oct(0o444)
dir_mode = oct(0o2775 if group else (0o777 & ~umask))
expected = {
os.path.join(cache_dir, "17"): dir_mode,
os.path.join(
cache_dir, "17", "4eaa1dd94050255b7b98a7e1924b31.dir"
): file_mode,
os.path.join(cache_dir, "97"): dir_mode,
os.path.join(
cache_dir, "97", "e17781c198500e2766ea56bd697c03"
): file_mode,
os.path.join(cache_dir, "d1"): dir_mode,
os.path.join(
cache_dir, "d1", "0b4c3ff123b26dc068d43a8bef2d23"
): file_mode,
}
assert expected == actual
def test_cache_dir_local(tmp_dir, dvc, caplog):