Skip to content

Commit

Permalink
Fix encoding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkhood148 committed Mar 4, 2024
1 parent 9ac6571 commit 68a4f30
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pycdlib/pycdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ def _seek_to_extent(self, extent):
self._cdfp.seek(extent * self.logical_block_size)

@lru_cache(maxsize=256)
def _find_iso_record(self, iso_path):
# type: (bytes) -> dr.DirectoryRecord
def _find_iso_record(self, iso_path, encoding='utf-8'):
# type: (bytes, str) -> dr.DirectoryRecord
"""
An internal method to find a directory record on the ISO given an ISO
path. If the entry is found, it returns the directory record object
Expand All @@ -731,7 +731,7 @@ def _find_iso_record(self, iso_path):
Returns:
The directory record entry representing the entry on the ISO.
"""
return _find_dr_record_by_name(self.pvd, iso_path, 'utf-8')
return _find_dr_record_by_name(self.pvd, iso_path, encoding)

@lru_cache(maxsize=256)
def _find_rr_record(self, rr_path):
Expand Down Expand Up @@ -3487,8 +3487,8 @@ def _rm_joliet_dir(self, joliet_path):

return num_bytes_to_remove

def _get_iso_entry(self, iso_path):
# type: (bytes) -> dr.DirectoryRecord
def _get_iso_entry(self, iso_path, encoding='utf-8'):
# type: (bytes, str) -> dr.DirectoryRecord
"""
Internal method to get the directory record for an ISO path.
Expand All @@ -3500,7 +3500,7 @@ def _get_iso_entry(self, iso_path):
if self._needs_reshuffle:
self._reshuffle_extents()

return self._find_iso_record(iso_path)
return self._find_iso_record(iso_path, encoding)

def _get_rr_entry(self, rr_path):
# type: (bytes) -> dr.DirectoryRecord
Expand Down Expand Up @@ -5475,6 +5475,8 @@ def list_children(self, **kwargs):
if key in ('joliet_path', 'rr_path', 'iso_path', 'udf_path'):
if value is not None:
num_paths += 1
elif key in ('encoding'):
continue
else:
raise pycdlibexception.PyCdlibInvalidInput("Invalid keyword, must be one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'")

Expand All @@ -5497,7 +5499,7 @@ def list_children(self, **kwargs):
rec = self._get_rr_entry(utils.normpath(kwargs['rr_path']))
use_rr = True
else:
rec = self._get_iso_entry(utils.normpath(kwargs['iso_path']))
rec = self._get_iso_entry(utils.normpath(kwargs['iso_path']), kwargs['encoding'])

for c in _yield_children(rec, use_rr):
yield c
Expand Down Expand Up @@ -5642,8 +5644,8 @@ def rm_isohybrid(self):

self.isohybrid_mbr = None

def full_path_from_dirrecord(self, rec, rockridge=False):
# type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry], bool) -> str
def full_path_from_dirrecord(self, rec, user_encoding, rockridge=False):
# type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry], str, bool) -> str
"""
Get the absolute path of a directory record.
Expand All @@ -5662,6 +5664,8 @@ def full_path_from_dirrecord(self, rec, rockridge=False):
if self.joliet_vd is not None and id(rec.vd) == id(self.joliet_vd):
encoding = 'utf-16_be'

if user_encoding:
encoding = user_encoding
# A root entry has no Rock Ridge entry, even on a Rock Ridge ISO.
# Always return / here.
if rec.is_root:
Expand Down Expand Up @@ -5701,6 +5705,8 @@ def full_path_from_dirrecord(self, rec, rockridge=False):
encoding = rec.file_ident.encoding
else:
encoding = 'utf-8'
if user_encoding:
encoding = user_encoding
udf_rec = rec # type: Optional[udfmod.UDFFileEntry]
while udf_rec is not None:
ident = udf_rec.file_identifier()
Expand Down Expand Up @@ -5913,13 +5919,13 @@ def walk(self, **kwargs):
while dirs:
dir_record = dirs.popleft()

relpath = self.full_path_from_dirrecord(dir_record,
relpath = self.full_path_from_dirrecord(dir_record, user_encoding,
rockridge=path_type == 'rr_path')
dirlist = []
filelist = []
dirdict = {}

for child in reversed(list(self.list_children(**{path_type: relpath}))):
for child in reversed(list(self.list_children(**{path_type: relpath, 'encoding': kwargs['encoding']}))):
if child is None or child.is_dot() or child.is_dotdot():
continue

Expand Down

0 comments on commit 68a4f30

Please sign in to comment.