[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Checking if a file's a tarball could fail due to permissions
commit e69cb95f93d6646e809bf0143ff595dae32a2b5e
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Apr 17 08:42:40 2012 -0700
Checking if a file's a tarball could fail due to permissions
I encountered a transient IOError from the tarfile.is_tarfile() call. I'm still
not sure why it complained about '/vmlinuz.old' (and the test actually still
passed), but it's inappropriate for the reader to raise an IOError there.
Falling back to mime type.
---
stem/descriptor/reader.py | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 01f8809..83b29c6 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -371,10 +371,19 @@ class DescriptorReader:
target_type = mimetypes.guess_type(target)
+ # Checking if it's a tar file may fail due to permissions so failing back
+ # to the mime type...
+ # IOError: [Errno 13] Permission denied: '/vmlinuz.old'
+
+ try:
+ is_tar = tarfile.is_tarfile(target)
+ except IOError:
+ is_tar = target_type[0] == 'application/x-tar'
+
if target_type[0] in (None, 'text/plain'):
# either '.txt' or an unknown type
self._handle_descriptor_file(target)
- elif tarfile.is_tarfile(target):
+ elif is_tar:
# handles gzip, bz2, and decompressed tarballs among others
self._handle_archive(target)
else:
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits