From 2ed7e5a6cc1df83bcb3e4814845232ee9a6e0ab5 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 27 Jun 2024 10:45:48 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=9D=E7=95=99=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/libraryduplicatecheck/__init__.py | 30 +++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/plugins/libraryduplicatecheck/__init__.py b/plugins/libraryduplicatecheck/__init__.py index 92781e9..a53b103 100644 --- a/plugins/libraryduplicatecheck/__init__.py +++ b/plugins/libraryduplicatecheck/__init__.py @@ -208,7 +208,7 @@ class LibraryDuplicateCheck(_PluginBase): if str(self._retain_type) != "仅检查": # Decide which file to keep based on criteria (e.g., file size or creation date) - keep_path = self.__choose_file_to_keep(paths) + keep_path = self.__choose_file_to_keep(paths, self._retain_type) logger.info(f"文件保留规则:{str(self._retain_type)} Keeping: {keep_path}") # Delete the other duplicate files (if needed) for path in paths: @@ -255,15 +255,31 @@ class LibraryDuplicateCheck(_PluginBase): logger.warn(f"{file_type}目录 {parent_path} 已删除") @staticmethod - def __choose_file_to_keep(paths): + def __choose_file_to_keep(paths, retain_type): # Example: Choose based on file size (keeping the smallest) - smallest_size = float('inf') + checked = float('inf') smallest_path = None for path in paths: - file_size = os.path.getmtime(path) - if file_size < smallest_size: - smallest_size = file_size - smallest_path = path + if str(retain_type) == "保留体积最小": + selected = os.path.getsize(path) + if selected < checked: + checked = selected + smallest_path = path + if str(retain_type) == "保留体积最大": + selected = os.path.getsize(path) + if selected > checked: + checked = selected + smallest_path = path + if str(retain_type) == "保留创建最早": + selected = os.path.getmtime(path) + if selected < checked: + checked = selected + smallest_path = path + if str(retain_type) == "保留创建最晚": + selected = os.path.getmtime(path) + if selected > checked: + checked = selected + smallest_path = path return smallest_path def __update_config(self):