Skip to content

Commit b8d448c

Browse files
authored
fix multifs listdir bug (#150)
1 parent df39ec1 commit b8d448c

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [2.0.20] - 2018-03-13
8+
9+
### Fixed
10+
11+
- MultiFS.listdir now correctly filters out duplicates
12+
713
## [2.0.19] - 2018-03-11
814

915
### Fixed

fs/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version, used in module and setup.py.
22
"""
3-
__version__ = "2.0.19"
3+
__version__ = "2.0.20"

fs/multifs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import unicode_literals
66
from __future__ import print_function
77

8-
from collections import namedtuple
8+
from collections import namedtuple, OrderedDict
99
from operator import itemgetter
1010

1111
from six import text_type
@@ -203,6 +203,7 @@ def listdir(self, path):
203203
exists = True
204204
if not exists:
205205
raise errors.ResourceNotFound(path)
206+
directory = list(OrderedDict.fromkeys(directory))
206207
return directory
207208

208209
def makedir(self, path, permissions=None, recreate=False):

tests/test_multifs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,13 @@ def test_no_writable(self):
134134
def test_validate_path(self):
135135
self.fs.write_fs = None
136136
self.fs.validatepath('foo')
137+
138+
def test_listdir_duplicates(self):
139+
m1 = MemoryFS()
140+
m2 = MemoryFS()
141+
m1.touch('foo')
142+
m2.touch('foo')
143+
multi_fs = MultiFS()
144+
multi_fs.add_fs('m1', m1)
145+
multi_fs.add_fs('m2', m2)
146+
self.assertEqual(multi_fs.listdir(u'/'), ['foo'])

0 commit comments

Comments
 (0)