mirror of https://github.com/CIRCL/PyCIRCLean
Proper handling of symlinks
parent
66dc401727
commit
936fc2c2a2
|
@ -213,7 +213,10 @@ class KittenGroomerFileCheck(KittenGroomerBase):
|
|||
# ##### Discarded mime types, reason in the comments ######
|
||||
def inode(self):
|
||||
''' Usually empty file. No reason (?) to copy it on the dest key'''
|
||||
self.cur_file.log_string += 'Inode file'
|
||||
if self.cur_file.is_symlink():
|
||||
self.cur_file.log_string += 'Symlink to {}'.format(self.log_details['symlink'])
|
||||
else:
|
||||
self.cur_file.log_string += 'Inode file'
|
||||
|
||||
def unknown(self):
|
||||
''' This main type is unknown, that should not happen '''
|
||||
|
|
|
@ -66,6 +66,12 @@ class FileBase(object):
|
|||
return True
|
||||
return False
|
||||
|
||||
def is_symlink(self):
|
||||
if self.has_mimetype() and self.main_type == 'inode' and self.sub_type == 'symlink':
|
||||
self.log_details.update({'symlink': os.readlink(self.src_path)})
|
||||
return True
|
||||
return False
|
||||
|
||||
def add_log_details(self, key, value):
|
||||
'''
|
||||
Add an entry in the log dictionary
|
||||
|
@ -165,9 +171,11 @@ class KittenGroomerBase(object):
|
|||
files = sorted(os.listdir(base_dir))
|
||||
for f in files:
|
||||
curpath = os.path.join(base_dir, f)
|
||||
if os.path.isdir(curpath):
|
||||
if os.path.islink(curpath):
|
||||
lf.write('{}+-- {}\t- Symbolic link to {}\n'.format(padding, f, os.readlink(curpath)))
|
||||
elif os.path.isdir(curpath):
|
||||
self.tree(curpath, padding)
|
||||
else:
|
||||
elif os.path.isfile(curpath):
|
||||
lf.write('{}+-- {}\t- {}\n'.format(padding, f, self._computehash(curpath)))
|
||||
|
||||
# ##### Helpers #####
|
||||
|
|
Loading…
Reference in New Issue