Skip to content

Commit 1924447

Browse files
committed
Make sure adding object to a symlinked directory works
- see #215
1 parent c5a5dae commit 1924447

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGES.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ The release versions are PyPi releases.
55

66
#### New Features
77
* Added support for basic modes in fake `os.open()` ([#204](../../issues/204)).
8-
* Added fake `os.path.samefile` implementation ([#193](../../issues/193))
8+
* Added fake `os.path.samefile` implementation ([#193](../../issues/193)).
99
* Added support for `ns` argument in `os.utime()` (Python >= 3.3) ([#192](../../issues/192)).
1010
* Added nanosecond time members in `os.stat_result` (Python >= 3.3) ([#196](../../issues/196)).
1111

1212
#### Infrastructure
1313

1414
#### Fixes
15-
* Incorrect error handling during directory creation ([#209](../../issues/209))
16-
* Creating files in read-only directory was possible ([#203](../../issues/203))
15+
* Failed to create directory with symlink as parent ([#215](../../issues/215)).
16+
* Incorrect error handling during directory creation ([#209](../../issues/209)).
17+
* Creating files in read-only directory was possible ([#203](../../issues/203)).
1718

1819
## [Version 3.2](https://pypi.python.org/pypi/pyfakefs/3.2)
1920

fake_filesystem_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,15 @@ def testMkdirRaisesIfParentIsReadOnly(self):
14571457
directory = '/a/b'
14581458
self.assertRaises(Exception, self.os.mkdir, directory)
14591459

1460+
def testMkdirWithWithSymlinkParent(self):
1461+
dir_path = '/foo/bar'
1462+
self.filesystem.CreateDirectory(dir_path)
1463+
link_path = '/foo/link'
1464+
self.os.symlink(dir_path, link_path)
1465+
new_dir = link_path + '/new_dir'
1466+
self.os.mkdir(new_dir)
1467+
self.assertTrue(self.filesystem.Exists(new_dir))
1468+
14601469
def testMakedirs(self):
14611470
"""makedirs can create a directory even if parent does not exist."""
14621471
parent = 'xyzzy'

pyfakefs/fake_filesystem.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,10 @@ def AddObject(self, file_path, file_object):
17731773
IOError: if file_path does not correspond to a directory.
17741774
"""
17751775
try:
1776-
target_directory = self.GetObject(file_path)
1776+
if not file_path:
1777+
target_directory = self.root
1778+
else:
1779+
target_directory = self.ResolveObject(file_path)
17771780
target_directory.AddEntry(file_object)
17781781
except AttributeError:
17791782
raise IOError(errno.ENOTDIR,

0 commit comments

Comments
 (0)