Skip to content

Commit

Permalink
Fix incorrect check for symlink in fake os.walk
Browse files Browse the repository at this point in the history
- proposed by @giladreti
- fixes #559
  • Loading branch information
mrbean-bremen committed Oct 17, 2020
1 parent e90bbd5 commit 981865a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The released versions correspond to PyPi releases.
* add possibility to set file system OS via `FakeFilesystem.os`

#### Fixes
* fix check for link in `os.walk` (see [#559](../../issues/559))
* fix handling of real files in combination with `home` if simulating
Posix under Windows (see [#558](../../issues/558))
* do not call fake `open` if called from skipped module
Expand Down
7 changes: 3 additions & 4 deletions pyfakefs/fake_scandir.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,11 @@ def do_walk(top_dir, top_most=False):
yield top_contents

for directory in top_contents[1]:
if not followlinks and filesystem.islink(directory):
path = filesystem.joinpaths(top_dir, directory)
if not followlinks and filesystem.islink(path):
continue
for contents in do_walk(filesystem.joinpaths(top_dir,
directory)):
for contents in do_walk(path):
yield contents

if not topdown:
yield top_contents

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 @@ -4572,6 +4572,20 @@ def test_walk_followsymlink_enabled(self):
self.os.path.join(base_dir, 'created_link'),
followlinks=True)

def test_walk_linked_file_in_subdir(self):
# regression test for #559 (tested for link on incomplete path)
self.check_posix_only()
# need to have a top-level link to reproduce the bug - skip real fs
self.skip_real_fs()
file_path = '/foo/bar/baz'
self.create_file(file_path)
self.create_symlink('bar', file_path)
expected = [
('/foo', ['bar'], []),
('/foo/bar', [], ['baz'])
]
self.assertWalkResults(expected, '/foo')

def test_base_dirpath(self):
# regression test for #512
file_path = self.make_path('foo', 'bar', 'baz')
Expand Down

0 comments on commit 981865a

Please sign in to comment.