[filesystem] in listDirectory, always use Unix '/' as separator

the _NOFS implementation is using `os.listdir` which uses the
native `os.sep`; however, pyfilesystem2 FS paths always uses forward
slashes '/'.
This commit is contained in:
Cosimo Lupo 2017-07-21 16:40:28 +01:00
parent 2bef40c30d
commit ec8d58f0b8
2 changed files with 8 additions and 4 deletions

View File

@ -204,8 +204,9 @@ class FileSystem(object):
return self._listDirectory(path, recurse=recurse, relativeTo=path)
def _listDirectory(self, path, recurse=False, relativeTo=None, depth=0, maxDepth=100):
if not relativeTo.endswith("/"):
relativeTo += "/"
sep = os.sep
if not relativeTo.endswith(sep):
relativeTo += sep
if depth > maxDepth:
raise UFOLibError("Maximum recusion depth reached.")
result = []
@ -215,6 +216,9 @@ class FileSystem(object):
result += self._listDirectory(p, recurse=True, relativeTo=relativeTo, depth=depth+1, maxDepth=maxDepth)
else:
p = p[len(relativeTo):]
if sep != "/":
# replace '\\' with '/'
path = path.replace(sep, "/")
result.append(p)
return result

View File

@ -4147,8 +4147,8 @@ class UFO3ReadDataTestCase(unittest.TestCase):
reader = UFOReader(self.getFontPath())
found = reader.getDataDirectoryListing()
expected = [
'org.unifiedfontobject.directory%(s)sbar%(s)slol.txt' % {'s': os.sep},
'org.unifiedfontobject.directory%(s)sfoo.txt' % {'s': os.sep},
'org.unifiedfontobject.directory/bar/lol.txt',
'org.unifiedfontobject.directory/foo.txt',
'org.unifiedfontobject.file.txt'
]
self.assertEqual(set(found), set(expected))