feat(wallpaper_changer): remove DOUBLE as identifier for duplcate filenames
available_path() function also continues numbering
This commit is contained in:
1 parent
27df6ce7f8
commit
8064bc1cd8
1 file changed
+15
-6
@@ -371,12 +371,21 @@ class ImageRepository:
|
||||
def _available_path(path: Path) -> Path:
|
||||
if not path.exists():
|
||||
return path
|
||||
counter = 1
|
||||
while True:
|
||||
candidate = path.with_name(f"{path.stem}_DOUBLE_{counter}{path.suffix}")
|
||||
if not candidate.exists():
|
||||
return candidate
|
||||
counter += 1
|
||||
match = re.fullmatch(r"(.*?)(\d+)", path.stem)
|
||||
prefix = match.group(1) if match else path.stem
|
||||
width = len(match.group(2)) if match else 2
|
||||
existing_numbers = []
|
||||
for existing_path in path.parent.glob("*"):
|
||||
if existing_path.suffix.casefold() != path.suffix.casefold():
|
||||
continue
|
||||
numbered_name = re.fullmatch(
|
||||
rf"{re.escape(prefix)}(\d+)", existing_path.stem, re.IGNORECASE
|
||||
)
|
||||
if numbered_name:
|
||||
existing_numbers.append(int(numbered_name.group(1)))
|
||||
|
||||
next_number = max(existing_numbers, default=0) + 1
|
||||
return path.with_name( f"{prefix}{next_number:0{width}d}{path.suffix}")
|
||||
|
||||
@staticmethod
|
||||
def _unique_identifier(identifier: str, naming_table: list[FileInfo]) -> str:
|
||||
|
||||
Reference in new issue
Block a user