Skip to content

Commit

Permalink
Correctly propagate "permission denied" error on creating directory
Browse files Browse the repository at this point in the history
- fixes #507
  • Loading branch information
mrbean-bremen committed Dec 20, 2019
1 parent d03db1f commit f14b9f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ the proposed changes so you can be ready.
#### New Features
* Added support for handling keyword-only arguments in some `os` functions

#### Fixes
* Fixed behavior of `os.makedirs` in write-protected directory
(see [#507](../../issues/507))

## [Version 3.7](https://pypi.python.org/pypi/pyfakefs/3.7)

This version adds support for Python 3.8.
Expand Down
3 changes: 3 additions & 0 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2854,6 +2854,9 @@ def makedirs(self, dir_name, mode=PERM_DEF, exist_ok=False):
try:
self.create_dir(dir_name, mode & ~self.umask)
except (IOError, OSError) as e:
if e.errno == errno.EACCES:
# permission denied - propagate exception
raise
if (not exist_ok or
not isinstance(self.resolve(dir_name), FakeDirectory)):
if self.is_windows_fs and e.errno == errno.ENOTDIR:
Expand Down
14 changes: 14 additions & 0 deletions pyfakefs/tests/fake_os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,20 @@ def test_makedirs_exist_ok(self):
self.os.makedirs(directory, exist_ok=True)
self.assertTrue(self.os.path.exists(directory))

def test_makedirs_in_write_protected_dir(self):
self.check_posix_only()
directory = self.make_path('foo')
self.os.mkdir(directory, mode=0o555)
subdir = self.os.path.join(directory, 'bar')
if not is_root():
self.assert_raises_os_error(errno.EACCES, self.os.makedirs,
subdir, exist_ok=True)
self.assert_raises_os_error(errno.EACCES, self.os.makedirs,
subdir, exist_ok=False)
else:
self.os.makedirs(subdir)
self.assertTrue(self.os.path.exists(subdir))

# test fsync and fdatasync
def test_fsync_raises_on_non_int(self):
self.assertRaises(TypeError, self.os.fsync, "zero")
Expand Down

0 comments on commit f14b9f9

Please sign in to comment.