Skip to content

Commit

Permalink
fix multifs listdir bug (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan authored Mar 13, 2018
1 parent df39ec1 commit b8d448c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.20] - 2018-03-13

### Fixed

- MultiFS.listdir now correctly filters out duplicates

## [2.0.19] - 2018-03-11

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion fs/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version, used in module and setup.py.
"""
__version__ = "2.0.19"
__version__ = "2.0.20"
3 changes: 2 additions & 1 deletion fs/multifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import unicode_literals
from __future__ import print_function

from collections import namedtuple
from collections import namedtuple, OrderedDict
from operator import itemgetter

from six import text_type
Expand Down Expand Up @@ -203,6 +203,7 @@ def listdir(self, path):
exists = True
if not exists:
raise errors.ResourceNotFound(path)
directory = list(OrderedDict.fromkeys(directory))
return directory

def makedir(self, path, permissions=None, recreate=False):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_multifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,13 @@ def test_no_writable(self):
def test_validate_path(self):
self.fs.write_fs = None
self.fs.validatepath('foo')

def test_listdir_duplicates(self):
m1 = MemoryFS()
m2 = MemoryFS()
m1.touch('foo')
m2.touch('foo')
multi_fs = MultiFS()
multi_fs.add_fs('m1', m1)
multi_fs.add_fs('m2', m2)
self.assertEqual(multi_fs.listdir(u'/'), ['foo'])

0 comments on commit b8d448c

Please sign in to comment.