nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: jmcgeheeiv/pyfakefs
Pull request #218 (2017-06-17 15:40:18)

Make sure adding object to a symlinked directory works
- see #215


Patch:
diff --git a/CHANGES.md b/CHANGES.md
index d12b8ea..c69b9ec 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -5,15 +5,16 @@ The release versions are PyPi releases.
 
 #### New Features
   * Added support for basic modes in fake `os.open()` ([#204](../../issues/204)). 
-  * Added fake `os.path.samefile` implementation ([#193](../../issues/193))
+  * Added fake `os.path.samefile` implementation ([#193](../../issues/193)).
   * Added support for `ns` argument in `os.utime()` (Python >= 3.3) ([#192](../../issues/192)).
   * Added nanosecond time members in `os.stat_result` (Python >= 3.3) ([#196](../../issues/196)).
 
 #### Infrastructure
 
 #### Fixes
-  * Incorrect error handling during directory creation ([#209](../../issues/209)) 
-  * Creating files in read-only directory was possible ([#203](../../issues/203))
+  * Failed to create directory with symlink as parent ([#215](../../issues/215)).
+  * Incorrect error handling during directory creation ([#209](../../issues/209)). 
+  * Creating files in read-only directory was possible ([#203](../../issues/203)).
 
 ## [Version 3.2](https://pypi.python.org/pypi/pyfakefs/3.2)
 
diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py
index 5d3ff7e..2ba02cf 100644
--- a/pyfakefs/fake_filesystem.py
+++ b/pyfakefs/fake_filesystem.py
@@ -1773,7 +1773,10 @@ class FakeFilesystem(object):
           IOError: if file_path does not correspond to a directory.
         """
         try:
-            target_directory = self.GetObject(file_path)
+            if not file_path:
+                target_directory = self.root
+            else:
+                target_directory = self.ResolveObject(file_path)
             target_directory.AddEntry(file_object)
         except AttributeError:
             raise IOError(errno.ENOTDIR,


Test patch:
diff --git a/fake_filesystem_test.py b/fake_filesystem_test.py
index b1e8637..8e92184 100755
--- a/fake_filesystem_test.py
+++ b/fake_filesystem_test.py
@@ -1457,6 +1457,15 @@ class FakeOsModuleTest(FakeOsModuleTestBase):
         directory = '/a/b'
         self.assertRaises(Exception, self.os.mkdir, directory)
 
+    def testMkdirWithWithSymlinkParent(self):
+        dir_path = '/foo/bar'
+        self.filesystem.CreateDirectory(dir_path)
+        link_path = '/foo/link'
+        self.os.symlink(dir_path, link_path)
+        new_dir = link_path + '/new_dir'
+        self.os.mkdir(new_dir)
+        self.assertTrue(self.filesystem.Exists(new_dir))
+
     def testMakedirs(self):
         """makedirs can create a directory even if parent does not exist."""
         parent = 'xyzzy'