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:
|
def _available_path(path: Path) -> Path:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return path
|
return path
|
||||||
counter = 1
|
match = re.fullmatch(r"(.*?)(\d+)", path.stem)
|
||||||
while True:
|
prefix = match.group(1) if match else path.stem
|
||||||
candidate = path.with_name(f"{path.stem}_DOUBLE_{counter}{path.suffix}")
|
width = len(match.group(2)) if match else 2
|
||||||
if not candidate.exists():
|
existing_numbers = []
|
||||||
return candidate
|
for existing_path in path.parent.glob("*"):
|
||||||
counter += 1
|
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
|
@staticmethod
|
||||||
def _unique_identifier(identifier: str, naming_table: list[FileInfo]) -> str:
|
def _unique_identifier(identifier: str, naming_table: list[FileInfo]) -> str:
|
||||||
|
|||||||
Reference in new issue
Block a user