vnrecode: fix duplicates check for case insensitive fs

This commit is contained in:
OleSTEEP 2024-09-04 04:30:01 +03:00
parent 90a6b4e0c1
commit 0b43756ef5
2 changed files with 7 additions and 5 deletions

View file

@ -42,7 +42,7 @@ class Application:
with ThreadPoolExecutor(max_workers=self.params.workers) as executor:
futures = [
executor.submit(self.compress, folder, file, source, output)
for file in files if os.path.isfile(f'{folder}/{file}')
for file in files if os.path.isfile(os.path.join(folder, file))
]
for future in as_completed(futures):
future.result()

View file

@ -4,6 +4,9 @@ import sys
import os
import re
import fnmatch
class Utils:
def __init__(self, params, printer):
@ -64,12 +67,11 @@ class Utils:
self.printer.info(f"File {filename} copied to compressed folder.")
def check_duplicates(self, source: str, output: str, filename: str) -> str:
files = glob(os.path.join(source, os.path.splitext(filename)[0])+".*")
re_pattern = re.compile(os.path.join(source, os.path.splitext(filename)[0])+r".[a-zA-Z0-9]+$")
duplicates = [f for f in files if re_pattern.match(f)]
re_pattern = re.compile(os.path.splitext(filename)[0]+r".[a-zA-Z0-9]+$", re.IGNORECASE)
duplicates = [name for name in os.listdir(source) if re_pattern.match(name)]
if len(duplicates) > 1:
if filename not in self.duplicates:
if filename.lower() not in (duplicate.lower() for duplicate in self.duplicates):
self.duplicates.append(filename)
new_name = os.path.splitext(filename)[0] + "(vncopy)" + os.path.splitext(filename)[1]
return os.path.join(output, new_name)