From b8d448cab205f6358894c99ef68b954e5156d6fa Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 13 Mar 2018 10:54:01 +0000 Subject: [PATCH] fix multifs listdir bug (#150) --- CHANGELOG.md | 6 ++++++ fs/_version.py | 2 +- fs/multifs.py | 3 ++- tests/test_multifs.py | 10 ++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c614cd1..237e479a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/fs/_version.py b/fs/_version.py index c016fb0a..aff8a833 100644 --- a/fs/_version.py +++ b/fs/_version.py @@ -1,3 +1,3 @@ """Version, used in module and setup.py. """ -__version__ = "2.0.19" +__version__ = "2.0.20" diff --git a/fs/multifs.py b/fs/multifs.py index 3860520c..8caf9228 100644 --- a/fs/multifs.py +++ b/fs/multifs.py @@ -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 @@ -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): diff --git a/tests/test_multifs.py b/tests/test_multifs.py index 974cdd23..c9dcc747 100644 --- a/tests/test_multifs.py +++ b/tests/test_multifs.py @@ -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'])