Skip to content

Commit

Permalink
dvc: ignore errors on protect/set_exec (bp #5335) (#5336)
Browse files Browse the repository at this point in the history
* dvc: ignore errors on protect/set_exec (#5335)

Both of these are not fatal and could safely be ignored.

Fixes #5255

(cherry picked from commit 434cd30)

* tests: upgrade azurite and enable loose mode

Backport of #5272

Co-authored-by: Ruslan Kuprieiev <[email protected]>
Co-authored-by: Ruslan Kuprieiev <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2021
1 parent 9638dde commit 7fe0279
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 34 deletions.
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

0 comments on commit 7fe0279

Please sign in to comment.