Skip to content

Commit

Permalink
Fix fileInDir and listDir
Browse files Browse the repository at this point in the history
  • Loading branch information
pfirsich committed May 4, 2018
1 parent 5a16aae commit ecd65fd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions gciso/gciso.py
Expand Up @@ -237,6 +237,13 @@ def readFile(self, path, offset, count=-1):
fileOffset, fileSize = self.files[path]
return self._readFile(fileOffset, fileSize, offset, count)

@staticmethod
def _normalizeDirPath(path):
if len(path) > 0: # empty path = root => can stay empty
if path[-1] != b"/"[0]: path += b"/" # add training slash
if path[0] == b"/"[0]: path = path[1:] # remove leading slash
return path

@staticmethod
def fileInDir(filePath, dirPath):
"""
Expand All @@ -252,8 +259,8 @@ def fileInDir(filePath, dirPath):
"""
IsoFile._checkPath(filePath)
IsoFile._checkPath(dirPath)
if dirPath[-1] != b"/"[0]: dirPath += b"/"
if dirPath == "/": return True
dirPath = IsoFile._normalizeDirPath(dirPath)
if dirPath == "": return True
return filePath.startswith(dirPath)

def listDir(self, path):
Expand All @@ -270,7 +277,7 @@ def listDir(self, path):
Filenames of the files in the directory. Relative to the directory being listed.
"""
IsoFile._checkPath(path)
if path[-1] != b"/"[0]: path += b"/"
path = IsoFile._normalizeDirPath(path)
for file in self.files:
if IsoFile.fileInDir(file, path):
yield file[len(path):]
Expand Down

0 comments on commit ecd65fd

Please sign in to comment.