diff --git a/CHANGES.md b/CHANGES.md index c69b9ecc..6d7bbf1a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ The release versions are PyPi releases. #### Infrastructure #### Fixes + * Incorrect handling of symlinks in `os.path.size` and other functions ([#210](../../issues/210)). * 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)). diff --git a/fake_filesystem_test.py b/fake_filesystem_test.py index 8e921842..1c1313a3 100755 --- a/fake_filesystem_test.py +++ b/fake_filesystem_test.py @@ -632,6 +632,15 @@ def testGetsize(self): self.filesystem.CreateFile(file_path, contents='1234567') self.assertEqual(7, self.path.getsize('FOO/BAR/BAZ')) + def testGetsizeWithLoopingSymlink(self): + self.filesystem.is_windows_fs = False + dir_path = '/foo/bar' + self.filesystem.CreateDirectory(dir_path) + link_path = dir_path + "/link" + link_target = link_path + "/link" + self.os.symlink(link_target, link_path) + self.assertRaisesOSError(errno.ELOOP, self.os.path.getsize, link_path) + def testGetMtime(self): test_file = self.filesystem.CreateFile('foo/bar1.txt') test_file.SetMTime(24) @@ -1458,6 +1467,7 @@ def testMkdirRaisesIfParentIsReadOnly(self): self.assertRaises(Exception, self.os.mkdir, directory) def testMkdirWithWithSymlinkParent(self): + self.filesystem.is_windows_fs = False dir_path = '/foo/bar' self.filesystem.CreateDirectory(dir_path) link_path = '/foo/link' @@ -1494,9 +1504,9 @@ def testMakedirsRaisesIfParentIsBrokenLink(self): def testMakedirsRaisesIfParentIsLoopingLink(self): dir_path = '/foo/bar' self.filesystem.CreateDirectory(dir_path) - link_target = dir_path + "/link" - link_path = link_target + "/link" - self.os.symlink(link_path, link_target) + link_path = dir_path + "/link" + link_target = link_path + "/link" + self.os.symlink(link_target, link_path) self.assertRaisesOSError(errno.ELOOP, self.os.makedirs, link_path) def testMakedirsRaisesIfAccessDenied(self): diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py index 2ba02cfb..0876020e 100644 --- a/pyfakefs/fake_filesystem.py +++ b/pyfakefs/fake_filesystem.py @@ -2644,7 +2644,7 @@ def getsize(self, path): file size in bytes. """ try: - file_obj = self.filesystem.GetObject(path) + file_obj = self.filesystem.ResolveObject(path) return file_obj.st_size except IOError as exc: raise os.error(exc.errno, exc.strerror) @@ -2698,7 +2698,7 @@ def getmtime(self, path): OSError: if the file does not exist. """ try: - file_obj = self.filesystem.GetObject(path) + file_obj = self.filesystem.ResolveObject(path) except IOError as exc: raise OSError(errno.ENOENT, str(exc)) return file_obj.st_mtime @@ -2718,7 +2718,7 @@ def getatime(self, path): OSError: if the file does not exist. """ try: - file_obj = self.filesystem.GetObject(path) + file_obj = self.filesystem.ResolveObject(path) except IOError as exc: raise OSError(errno.ENOENT, str(exc)) return file_obj.st_atime @@ -2736,7 +2736,7 @@ def getctime(self, path): OSError: if the file does not exist. """ try: - file_obj = self.filesystem.GetObject(path) + file_obj = self.filesystem.ResolveObject(path) except IOError as exc: raise OSError(errno.ENOENT, str(exc)) return file_obj.st_ctime diff --git a/tox.ini b/tox.ini index 2758e782..b6009d94 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py26,py27,py33,py34,py35,py36 +envlist=py26,py27,py33,py34,py35,py36,py37,pypy [testenv] deps = -rrequirements.txt