Do not fail on broken symlink

pull/2/head
Raphaël Vinot 2015-11-24 18:13:41 +01:00
parent 6bc83f947d
commit d6476dab38
1 changed files with 9 additions and 5 deletions

View File

@ -37,11 +37,15 @@ class FileBase(object):
self.log_string = '' self.log_string = ''
a, self.extension = os.path.splitext(self.src_path) a, self.extension = os.path.splitext(self.src_path)
mt = magic.from_file(self.src_path, mime=True) if os.path.islink(self.src_path):
try: # magic will throw an IOError on a broken symlink
self.mimetype = mt.decode("utf-8") self.mimetype = 'inode/symlink'
except: else:
self.mimetype = mt mt = magic.from_file(self.src_path, mime=True)
try:
self.mimetype = mt.decode("utf-8")
except:
self.mimetype = mt
if self.mimetype and '/' in self.mimetype: if self.mimetype and '/' in self.mimetype:
self.main_type, self.sub_type = self.mimetype.split('/') self.main_type, self.sub_type = self.mimetype.split('/')