Skip to content

Commit

Permalink
Merge pull request conda#8665 from chrisburr/read-only-filesystems
Browse files Browse the repository at this point in the history
Handle errors from read only filesystems
  • Loading branch information
msarahan authored May 14, 2019
2 parents ca5b45b + 2ad4de2 commit 7c3020c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions conda/core/package_cache_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import codecs
from errno import EACCES, ENOENT, EPERM
from errno import EACCES, ENOENT, EPERM, EROFS
from functools import reduce
from logging import getLogger
from os import listdir
Expand Down Expand Up @@ -402,7 +402,7 @@ def _make_single_record(self, package_filename):
try:
write_as_json_to_file(repodata_record_path, repodata_record)
except (IOError, OSError) as e:
if e.errno in (EACCES, EPERM) and isdir(dirname(repodata_record_path)):
if e.errno in (EACCES, EPERM, EROFS) and isdir(dirname(repodata_record_path)):
raise NotWritableError(repodata_record_path, e.errno, caused_by=e)
else:
raise
Expand Down
4 changes: 2 additions & 2 deletions conda/core/subdir_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import bz2
from collections import defaultdict
from contextlib import closing
from errno import EACCES, ENODEV, EPERM
from errno import EACCES, ENODEV, EPERM, EROFS
from genericpath import getmtime, isfile
import hashlib
import json
Expand Down Expand Up @@ -230,7 +230,7 @@ def _load(self):
with io_open(self.cache_path_json, 'w') as fh:
fh.write(raw_repodata_str or '{}')
except (IOError, OSError) as e:
if e.errno in (EACCES, EPERM):
if e.errno in (EACCES, EPERM, EROFS):
raise NotWritableError(self.cache_path_json, e.errno, caused_by=e)
else:
raise
Expand Down
6 changes: 3 additions & 3 deletions conda/gateways/disk/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import codecs
from errno import EACCES, EPERM
from errno import EACCES, EPERM, EROFS
from io import open
from logging import getLogger
import os
Expand Down Expand Up @@ -392,7 +392,7 @@ def create_package_cache_directory(pkgs_dir):
touch(join(pkgs_dir, PACKAGE_CACHE_MAGIC_FILE), mkdir=True, sudo_safe=sudo_safe)
touch(join(pkgs_dir, 'urls'), sudo_safe=sudo_safe)
except (IOError, OSError) as e:
if e.errno in (EACCES, EPERM):
if e.errno in (EACCES, EPERM, EROFS):
log.trace("cannot create package cache directory '%s'", pkgs_dir)
return False
else:
Expand All @@ -412,7 +412,7 @@ def create_envs_directory(envs_dir):
sudo_safe = expand(envs_dir).startswith(expand('~'))
touch(join(envs_dir, envs_dir_magic_file), mkdir=True, sudo_safe=sudo_safe)
except (IOError, OSError) as e:
if e.errno in (EACCES, EPERM):
if e.errno in (EACCES, EPERM, EROFS):
log.trace("cannot create envs directory '%s'", envs_dir)
return False
else:
Expand Down
4 changes: 2 additions & 2 deletions conda/gateways/disk/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause
from __future__ import absolute_import, division, print_function, unicode_literals

from errno import EACCES, ENOENT, EPERM
from errno import EACCES, ENOENT, EPERM, EROFS
from itertools import chain
from logging import getLogger
from os import X_OK, access, chmod, lstat, walk
Expand Down Expand Up @@ -34,7 +34,7 @@ def make_writable(path):
if eno in (ENOENT,):
log.debug("tried to make writable, but didn't exist: %s", path)
raise
elif eno in (EACCES, EPERM):
elif eno in (EACCES, EPERM, EROFS):
log.debug("tried make writable but failed: %s\n%r", path, e)
return False
else:
Expand Down
4 changes: 2 additions & 2 deletions conda/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ast import literal_eval
import codecs
from errno import EACCES, EPERM
from errno import EACCES, EPERM, EROFS
import logging
from operator import itemgetter
import os
Expand Down Expand Up @@ -114,7 +114,7 @@ def update(self):
curr = set(prefix_rec.dist_str() for prefix_rec in pd.iter_records())
self.write_changes(last, curr)
except EnvironmentError as e:
if e.errno in (EACCES, EPERM):
if e.errno in (EACCES, EPERM, EROFS):
raise NotWritableError(self.path, e.errno)
else:
raise
Expand Down
20 changes: 19 additions & 1 deletion tests/gateways/disk/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import errno
import pytest
from errno import ENOENT, EACCES
from errno import ENOENT, EACCES, EROFS, EPERM
from shutil import rmtree
from contextlib import contextmanager
from tempfile import gettempdir
Expand Down Expand Up @@ -104,6 +104,15 @@ def test_make_writable_doesnt_exist():


def test_make_writable_dir_EPERM():
import conda.gateways.disk.permissions
from conda.gateways.disk.permissions import make_writable
with patch.object(conda.gateways.disk.permissions, 'chmod') as chmod_mock:
chmod_mock.side_effect = IOError(EPERM, 'some message', 'foo')
with tempdir() as td:
assert not make_writable(td)


def test_make_writable_dir_EACCES():
import conda.gateways.disk.permissions
from conda.gateways.disk.permissions import make_writable
with patch.object(conda.gateways.disk.permissions, 'chmod') as chmod_mock:
Expand All @@ -112,6 +121,15 @@ def test_make_writable_dir_EPERM():
assert not make_writable(td)


def test_make_writable_dir_EROFS():
import conda.gateways.disk.permissions
from conda.gateways.disk.permissions import make_writable
with patch.object(conda.gateways.disk.permissions, 'chmod') as chmod_mock:
chmod_mock.side_effect = IOError(EROFS, 'some message', 'foo')
with tempdir() as td:
assert not make_writable(td)


def test_recursive_make_writable():
from conda.gateways.disk.permissions import recursive_make_writable
with tempdir() as td:
Expand Down

0 comments on commit 7c3020c

Please sign in to comment.