More robust filename encoding during stdout handling

This commit is contained in:
Łukasz Langa 2016-10-29 19:09:08 -07:00
parent 8c871b1319
commit 5e66b772d2
3 changed files with 21 additions and 14 deletions

View File

@ -0,0 +1 @@
This is a form of testing strange encodings.

View File

@ -36,6 +36,14 @@ a 100 GB Aperture library in under 10 minutes. Both tests on HFS+.
Change Log
----------
0.9.1
~~~~~
* bugfix: print the path that failed to decode with FSENCODING
* bugfix: when using -q, don't hide warnings about files that can't be
statted or read
0.9.0
~~~~~

View File

@ -112,17 +112,10 @@ def list_existing_paths(directory, expected=(), ignored=(), follow_links=False):
try:
p_uni = p.decode(FSENCODING)
except UnicodeDecodeError:
try:
print(
"warning: cannot decode file name:",
p,
file=sys.stderr,
)
except UnicodeDecodeError:
# yup, even printing the filename might fail in certain
# occasions
pass
binary_stderr = getattr(sys.stderr, 'buffer', sys.stderr)
binary_stderr.write(b"warning: cannot decode file name: ")
binary_stderr.write(p)
binary_stderr.write(b"\n")
continue
try:
@ -326,17 +319,22 @@ class Bitrot(object):
print('{} entries new:'.format(len(new_paths)))
new_paths.sort()
for path in new_paths:
print(' ', path)
print(' ', path.decode(FSENCODING))
if updated_paths:
print('{} entries updated:'.format(len(updated_paths)))
updated_paths.sort()
for path in updated_paths:
print(' ', path)
print(' ', path.decode(FSENCODING))
if renamed_paths:
print('{} entries renamed:'.format(len(renamed_paths)))
renamed_paths.sort()
for path in renamed_paths:
print(' from', path[0], 'to', path[1])
print(
' from',
path[0].decode(FSENCODING),
'to',
path[1].decode(FSENCODING),
)
if missing_paths:
print('{} entries missing:'.format(len(missing_paths)))
missing_paths = sorted(missing_paths)