mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 23:09:35 +01:00
experiments: preserve file permissions across tmpdir execution (#4890)
* tree: use file_mode in upload() for trees that support modes * experiments: preserve file_mode for files in the workspace * skip permissions tests on windows * LocalTree: separate chmod from protect * fix rebase issue
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import stat
|
||||
|
||||
import pytest
|
||||
from funcy import first
|
||||
@@ -19,6 +21,18 @@ def test_new_simple(tmp_dir, scm, dvc, exp_stage, mocker):
|
||||
).read_text() == "foo: 2"
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name == "nt", reason="Not supported for Windows.")
|
||||
def test_file_permissions(tmp_dir, scm, dvc, exp_stage, mocker):
|
||||
mode = 0o755
|
||||
os.chmod(tmp_dir / "copy.py", mode)
|
||||
scm.add(["copy.py"])
|
||||
scm.commit("set exec")
|
||||
|
||||
tmp_dir.gen("params.yaml", "foo: 2")
|
||||
dvc.experiments.run(exp_stage.addressing)
|
||||
assert stat.S_IMODE(os.stat(tmp_dir / "copy.py").st_mode) == mode
|
||||
|
||||
|
||||
def test_failed_exp(tmp_dir, scm, dvc, exp_stage, mocker, caplog):
|
||||
from dvc.stage.exceptions import StageCmdFailedError
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import os
|
||||
import stat
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.config import ConfigError
|
||||
from dvc.path_info import CloudURLInfo
|
||||
from dvc.tree import get_cloud_tree
|
||||
from dvc.path_info import CloudURLInfo, PathInfo
|
||||
from dvc.tree import LocalTree, get_cloud_tree
|
||||
|
||||
|
||||
def test_get_cloud_tree(tmp_dir, dvc):
|
||||
@@ -46,3 +49,18 @@ def test_get_cloud_tree_validate(tmp_dir, dvc):
|
||||
|
||||
with pytest.raises(ConfigError):
|
||||
get_cloud_tree(dvc, name="second")
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name == "nt", reason="Not supported for Windows.")
|
||||
@pytest.mark.parametrize(
|
||||
"mode, expected", [(None, LocalTree.CACHE_MODE), (0o777, 0o777)],
|
||||
)
|
||||
def test_upload_file_mode(tmp_dir, mode, expected):
|
||||
tmp_dir.gen("src", "foo")
|
||||
src = PathInfo(tmp_dir / "src")
|
||||
dest = PathInfo(tmp_dir / "dest")
|
||||
tree = LocalTree(None, {"url": os.fspath(tmp_dir)})
|
||||
tree.upload(src, dest, file_mode=mode)
|
||||
assert (tmp_dir / "dest").exists()
|
||||
assert (tmp_dir / "dest").read_text() == "foo"
|
||||
assert stat.S_IMODE(os.stat(dest).st_mode) == expected
|
||||
|
||||
Reference in New Issue
Block a user