Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dvc: ignore errors on protect/set_exec (bp #5335) #5336

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions dvc/tree/local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import errno
import logging
import os
import stat
Expand Down Expand Up @@ -247,19 +246,11 @@ def chmod(self, path_info, mode):
path = os.fspath(path_info)
try:
os.chmod(path, mode)
except OSError as exc:
# There is nothing we need to do in case of a read-only file system
if exc.errno == errno.EROFS:
return

# In shared cache scenario, we might not own the cache file, so we
# need to check if cache file is already protected.
if exc.errno not in [errno.EPERM, errno.EACCES]:
raise

actual = stat.S_IMODE(os.stat(path).st_mode)
if actual != mode:
raise
except OSError:
# NOTE: not being able to protect cache file is not fatal, it
# might happen on funky filesystems (e.g. Samba, see #5255),
# read-only filesystems or in a shared cache scenario.
logger.trace("failed to protect '%s'", path_info, exc_info=True)

def _unprotect_file(self, path):
if System.is_symlink(path) or System.is_hardlink(path):
Expand Down
3 changes: 2 additions & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
version: '3.2'
services:
azurite:
image: mcr.microsoft.com/azure-storage/azurite:3.9.0
image: mcr.microsoft.com/azure-storage/azurite:3.10.0
command: azurite -L -l /data --blobHost 0.0.0.0 --queueHost 0.0.0.0
ports:
- "10000"
oss:
Expand Down
22 changes: 3 additions & 19 deletions tests/unit/remote/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,12 @@ def test_is_protected(tmp_dir, dvc, link_name):
assert tree.is_protected(foo)


@pytest.mark.parametrize("err", [errno.EPERM, errno.EACCES])
def test_protect_ignore_errors(tmp_dir, mocker, err):
@pytest.mark.parametrize("err", [errno.EPERM, errno.EACCES, errno.EROFS])
def test_protect_ignore_errors(tmp_dir, dvc, mocker, err):
tmp_dir.gen("foo", "foo")
foo = PathInfo("foo")
tree = LocalTree(None, {})

tree.protect(foo)

mock_chmod = mocker.patch(
"os.chmod", side_effect=OSError(err, "something")
)
tree.protect(foo)
assert mock_chmod.called


def test_protect_ignore_erofs(tmp_dir, mocker):
tmp_dir.gen("foo", "foo")
foo = PathInfo("foo")
tree = LocalTree(None, {})

mock_chmod = mocker.patch(
"os.chmod", side_effect=OSError(errno.EROFS, "read-only fs")
)
tree.protect(foo)
LocalTree(None, {}).protect(PathInfo("foo"))
assert mock_chmod.called