From dd29350f7fc973c2f8ce64a18aaa81c88b613065 Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Tue, 28 Dec 2021 22:47:48 +0100 Subject: [PATCH] log: add extra try except when removing log dirs and fix eni.d cp The extra try/except are necessary just in case something goes wrong we still want to go through the entire list of extra log dir present on the system. Signed-off-by: Julien Fortin --- ifupdown2/lib/log.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ifupdown2/lib/log.py b/ifupdown2/lib/log.py index ca30d4d..c0bf084 100644 --- a/ifupdown2/lib/log.py +++ b/ifupdown2/lib/log.py @@ -193,16 +193,19 @@ class LogManager: # cp ENI and ENI.d in the log directory shutil.copy2("/etc/network/interfaces", new_dir_path) try: - shutil.copytree("/etc/network/interfaces.d/", new_dir_path) - except FileNotFoundError: + shutil.copytree("/etc/network/interfaces.d/", "%s/interfaces.d" % new_dir_path) + except Exception: pass # remove extra directory logs if we are reaching the 'user_config_limit' len_ifupdown2_log_dirs = len(ifupdown2_log_dirs) if len_ifupdown2_log_dirs > user_config_limit: for index in range(0, len_ifupdown2_log_dirs - user_config_limit): - directory_to_remove = "%s/%s%s_%s" % (self.LOGGING_DIRECTORY, self.LOGGING_DIRECTORY_PREFIX, ifupdown2_log_dirs[index][0], ifupdown2_log_dirs[index][1]) - shutil.rmtree(directory_to_remove, ignore_errors=True) + try: + directory_to_remove = "%s/%s%s_%s" % (self.LOGGING_DIRECTORY, self.LOGGING_DIRECTORY_PREFIX, ifupdown2_log_dirs[index][0], ifupdown2_log_dirs[index][1]) + shutil.rmtree(directory_to_remove, ignore_errors=True) + except: + pass @staticmethod def __create_dir(path):