From 936fc2c2a2398860cc60c7e482ca54f990af4252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 24 Nov 2015 17:45:06 +0100 Subject: [PATCH] Proper handling of symlinks --- bin/filecheck.py | 5 ++++- kittengroomer/helpers.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/filecheck.py b/bin/filecheck.py index ce64f64..07cc6fd 100644 --- a/bin/filecheck.py +++ b/bin/filecheck.py @@ -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 ''' diff --git a/kittengroomer/helpers.py b/kittengroomer/helpers.py index ed1cd7f..52627d7 100644 --- a/kittengroomer/helpers.py +++ b/kittengroomer/helpers.py @@ -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 #####