Skip to content

Commit 981865a

Browse files
committed
Fix incorrect check for symlink in fake os.walk
- proposed by @giladreti - fixes #559
1 parent e90bbd5 commit 981865a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The released versions correspond to PyPi releases.
1212
* add possibility to set file system OS via `FakeFilesystem.os`
1313

1414
#### Fixes
15+
* fix check for link in `os.walk` (see [#559](../../issues/559))
1516
* fix handling of real files in combination with `home` if simulating
1617
Posix under Windows (see [#558](../../issues/558))
1718
* do not call fake `open` if called from skipped module

pyfakefs/fake_scandir.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,11 @@ def do_walk(top_dir, top_most=False):
241241
yield top_contents
242242

243243
for directory in top_contents[1]:
244-
if not followlinks and filesystem.islink(directory):
244+
path = filesystem.joinpaths(top_dir, directory)
245+
if not followlinks and filesystem.islink(path):
245246
continue
246-
for contents in do_walk(filesystem.joinpaths(top_dir,
247-
directory)):
247+
for contents in do_walk(path):
248248
yield contents
249-
250249
if not topdown:
251250
yield top_contents
252251

pyfakefs/tests/fake_os_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4572,6 +4572,20 @@ def test_walk_followsymlink_enabled(self):
45724572
self.os.path.join(base_dir, 'created_link'),
45734573
followlinks=True)
45744574

4575+
def test_walk_linked_file_in_subdir(self):
4576+
# regression test for #559 (tested for link on incomplete path)
4577+
self.check_posix_only()
4578+
# need to have a top-level link to reproduce the bug - skip real fs
4579+
self.skip_real_fs()
4580+
file_path = '/foo/bar/baz'
4581+
self.create_file(file_path)
4582+
self.create_symlink('bar', file_path)
4583+
expected = [
4584+
('/foo', ['bar'], []),
4585+
('/foo/bar', [], ['baz'])
4586+
]
4587+
self.assertWalkResults(expected, '/foo')
4588+
45754589
def test_base_dirpath(self):
45764590
# regression test for #512
45774591
file_path = self.make_path('foo', 'bar', 'baz')

0 commit comments

Comments
 (0)