Skip to content

Commit 5043dc5

Browse files
committed
v0.2.2: Sanitize new filenames immediately
I was previously only sanitizing *after* a rename failed; but this introduced a bug where names could include / and thus break the path-splitting logic. Makes more sense to just always sanitize anyway, so that the resulting filenames are portable. Fixes #11
1 parent 39c2fd6 commit 5043dc5

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

shroudstone/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Python utilities for working with Stormgate replays"""
22

3-
__version__ = "0.2.1"
3+
__version__ = "0.2.2"

shroudstone/renamer.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ def new_name_for(replay: Replay, format_1v1: str, format_generic: str) -> str:
300300
newname = format_generic.format(**parts)
301301

302302
# In case we left some blanks, collapse multiple spaces to one space
303-
return re.sub(r"\s+", " ", newname)
303+
newname = re.sub(r"\s+", " ", newname)
304+
305+
return sanitize_filename(newname)
304306

305307

306308
def do_rename(source: Path, target: Path, dry_run: bool):
@@ -320,15 +322,7 @@ def do_rename(source: Path, target: Path, dry_run: bool):
320322
try:
321323
source.rename(target)
322324
except Exception as e:
323-
# In case the error was due to weird characters in a player name:
324-
new_name = sanitize_filename(target.name)
325-
if new_name != target.name:
326-
logger.warning(
327-
f"Error renaming {source} => {target.name}, retrying with sanitized filename."
328-
)
329-
do_rename(source, target.parent / new_name, dry_run=dry_run)
330-
else:
331-
logger.error(f"Error renaming {source} => {target.name}: {e}")
325+
logger.error(f"Error renaming {source} => {target.name}: {e}")
332326

333327

334328
def sanitize_filename(filename: str) -> str:

0 commit comments

Comments
 (0)