fix: eliminate duplicate wallpaper entries using realpath and file signature deduplication engine
This commit is contained in:
parent
bb6baa5f5e
commit
99c8d8c07f
@ -11,7 +11,8 @@ def scan_wallpapers():
|
||||
'/usr/share/backgrounds'
|
||||
]
|
||||
res = []
|
||||
seen = set()
|
||||
seen_realpaths = set()
|
||||
seen_file_signatures = set()
|
||||
|
||||
for base_dir in search_dirs:
|
||||
if not os.path.exists(base_dir):
|
||||
@ -20,11 +21,34 @@ def scan_wallpapers():
|
||||
for filename in files:
|
||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.webp', '.svg')):
|
||||
full_path = os.path.join(root, filename)
|
||||
if full_path in seen:
|
||||
continue
|
||||
seen.add(full_path)
|
||||
real_path = os.path.realpath(full_path)
|
||||
|
||||
if real_path in seen_realpaths:
|
||||
continue
|
||||
|
||||
try:
|
||||
file_size = os.path.getsize(full_path)
|
||||
except Exception:
|
||||
file_size = 0
|
||||
|
||||
# Determine parent variant name
|
||||
folder_name = os.path.basename(root)
|
||||
if folder_name.lower() in ("contents", "screenshots", "images"):
|
||||
parent_folder = os.path.basename(os.path.dirname(root))
|
||||
variant_name = parent_folder if parent_folder and parent_folder != os.path.basename(base_dir) else os.path.splitext(filename)[0]
|
||||
elif root != base_dir:
|
||||
variant_name = folder_name
|
||||
else:
|
||||
variant_name = os.path.splitext(filename)[0]
|
||||
|
||||
sig = (variant_name.lower(), filename.lower(), file_size)
|
||||
|
||||
if sig in seen_file_signatures:
|
||||
continue
|
||||
|
||||
seen_realpaths.add(real_path)
|
||||
seen_file_signatures.add(sig)
|
||||
|
||||
variant_name = os.path.basename(root) if root != base_dir else os.path.splitext(filename)[0]
|
||||
res.append({
|
||||
'variant': variant_name,
|
||||
'name': filename,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user