-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix filename decoding issue for zip files archived by macOS #75
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Wh1isper
I have a couple of suggestions. And could you update the workflow .github/workflows/build.yml
on all OSes, so the tests will cover this use case.
with reader as f: | ||
for fn in f.namelist(): | ||
extreact_path = pathlib.Path(f.extract(fn, path=destination)) | ||
correct_filename = try_macos_decode(fn) or try_windows_chinese_decode(fn) or fn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this a bit to use a single function that has the following structure:
def decode_filename(fn):
try:
encoded_filename = fn.encode('cp437')
try:
# MacOS encoding
return encoded_filename.decode('utf-8')
except UnicodeError:
# Windows encoding
return encoded_filename.decode('gbk')
except UnicodeError:
return fn
for fn in f.namelist(): | ||
extreact_path = pathlib.Path(f.extract(fn, path=destination)) | ||
correct_filename = try_macos_decode(fn) or try_windows_chinese_decode(fn) or fn | ||
extreact_path.rename(os.path.join(destination, correct_filename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destination
is a Path
, so you can write:
extreact_path.rename(os.path.join(destination, correct_filename)) | |
extracted_path.rename(destination / correct_filename) |
# *nix zip utilities silently uses system encoding(utf-8 generally) | ||
with reader as f: | ||
for fn in f.namelist(): | ||
extreact_path = pathlib.Path(f.extract(fn, path=destination)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix wording
extreact_path = pathlib.Path(f.extract(fn, path=destination)) | |
extracted_path = pathlib.Path(f.extract(fn, path=destination)) |
|
||
self.log.info("Finished extracting {} to {}.".format(archive_path, archive_destination)) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, I found this is not a good way to solve this problem |
this is how I fix #74