def test_is_protected(tmp_dir, dvc, link_name): remote = RemoteLOCAL(dvc, {}) link_method = getattr(remote, link_name) (tmp_dir / "foo").write_text("foo") foo = PathInfo(tmp_dir / "foo") link = PathInfo(tmp_dir / "link") link_method(foo, link) assert not remote.is_protected(foo) assert not remote.is_protected(link) remote.protect(foo) assert remote.is_protected(foo) assert remote.is_protected(link) remote.unprotect(link) assert not remote.is_protected(link) if os.name == "nt" and link_name == "hardlink": # NOTE: NTFS doesn't allow deleting read-only files, which forces us to # set write perms on the link, which propagates to the source. assert not remote.is_protected(foo) else: assert remote.is_protected(foo)
def test_is_protected(tmp_dir, link_name): remote = RemoteLOCAL(None, {}) link_method = getattr(remote, link_name) (tmp_dir / "foo").write_text("foo") foo = PathInfo(tmp_dir / "foo") link = PathInfo(tmp_dir / "link") link_method(foo, link) assert not remote.is_protected(foo) assert not remote.is_protected(link) remote.protect(foo) assert remote.is_protected(foo) assert remote.is_protected(link) remote.unprotect(link) assert not remote.is_protected(link) if link_name == "symlink" and os.name == "nt": # NOTE: Windows symlink perms don't propagate to the target assert remote.is_protected(foo) else: assert not remote.is_protected(foo)
def test_protect_ignore_erofs(tmp_dir, mocker): tmp_dir.gen("foo", "foo") foo = PathInfo("foo") remote = RemoteLOCAL(None, {}) mock_chmod = mocker.patch("os.chmod", side_effect=OSError(errno.EROFS, "read-only fs")) remote.protect(foo) assert mock_chmod.called
def test_protect_ignore_errors(tmp_dir, mocker, err): tmp_dir.gen("foo", "foo") foo = PathInfo("foo") remote = RemoteLOCAL(None, {}) remote.protect(foo) mock_chmod = mocker.patch("os.chmod", side_effect=OSError(err, "something")) remote.protect(foo) assert mock_chmod.called