Skip to content

Commit d3d535b

Browse files
committed
Annex: fix "is_pointer" method
"is_pointer" was failing when trying to read a binary file because a binary file cannot be decoded with UTF-8.
1 parent e81dfd0 commit d3d535b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/rift/Annex.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,22 @@ def is_pointer(cls, filepath):
231231
Return true if content of file at filepath looks like a valid digest
232232
identifier.
233233
"""
234-
with open(filepath, encoding='utf-8') as fh:
235-
identifier = fh.read()
236-
# Remove possible trailing whitespace, newline and carriage return
237-
# characters.
238-
identifier = identifier.rstrip()
234+
try:
235+
with open(filepath, encoding='utf-8') as fh:
236+
identifier = fh.read()
237+
# Remove possible trailing whitespace, newline and carriage return
238+
# characters.
239+
identifier = identifier.rstrip()
240+
241+
except UnicodeDecodeError:
242+
# Binary fileis cannot be decoded with UTF-8
243+
return False
239244

240245
# Check size corresponds to MD5 (32) or SHA3 256 (64).
241246
if len(identifier) in (32, 64):
242247
return all(byte in string.hexdigits for byte in identifier)
243248

249+
# If the identifier is not a valid Rift Annex pointer
244250
return False
245251

246252
def make_restore_cache(self):

0 commit comments

Comments
 (0)