[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:
parent
2bef40c30d
commit
ec8d58f0b8
@ -204,8 +204,9 @@ class FileSystem(object):
|
|||||||
return self._listDirectory(path, recurse=recurse, relativeTo=path)
|
return self._listDirectory(path, recurse=recurse, relativeTo=path)
|
||||||
|
|
||||||
def _listDirectory(self, path, recurse=False, relativeTo=None, depth=0, maxDepth=100):
|
def _listDirectory(self, path, recurse=False, relativeTo=None, depth=0, maxDepth=100):
|
||||||
if not relativeTo.endswith("/"):
|
sep = os.sep
|
||||||
relativeTo += "/"
|
if not relativeTo.endswith(sep):
|
||||||
|
relativeTo += sep
|
||||||
if depth > maxDepth:
|
if depth > maxDepth:
|
||||||
raise UFOLibError("Maximum recusion depth reached.")
|
raise UFOLibError("Maximum recusion depth reached.")
|
||||||
result = []
|
result = []
|
||||||
@ -215,6 +216,9 @@ class FileSystem(object):
|
|||||||
result += self._listDirectory(p, recurse=True, relativeTo=relativeTo, depth=depth+1, maxDepth=maxDepth)
|
result += self._listDirectory(p, recurse=True, relativeTo=relativeTo, depth=depth+1, maxDepth=maxDepth)
|
||||||
else:
|
else:
|
||||||
p = p[len(relativeTo):]
|
p = p[len(relativeTo):]
|
||||||
|
if sep != "/":
|
||||||
|
# replace '\\' with '/'
|
||||||
|
path = path.replace(sep, "/")
|
||||||
result.append(p)
|
result.append(p)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -4147,8 +4147,8 @@ class UFO3ReadDataTestCase(unittest.TestCase):
|
|||||||
reader = UFOReader(self.getFontPath())
|
reader = UFOReader(self.getFontPath())
|
||||||
found = reader.getDataDirectoryListing()
|
found = reader.getDataDirectoryListing()
|
||||||
expected = [
|
expected = [
|
||||||
'org.unifiedfontobject.directory%(s)sbar%(s)slol.txt' % {'s': os.sep},
|
'org.unifiedfontobject.directory/bar/lol.txt',
|
||||||
'org.unifiedfontobject.directory%(s)sfoo.txt' % {'s': os.sep},
|
'org.unifiedfontobject.directory/foo.txt',
|
||||||
'org.unifiedfontobject.file.txt'
|
'org.unifiedfontobject.file.txt'
|
||||||
]
|
]
|
||||||
self.assertEqual(set(found), set(expected))
|
self.assertEqual(set(found), set(expected))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user