fix safe_filename() on windows

This commit is contained in:
Lincoln Stein 2024-04-28 14:42:40 -04:00
parent f65c7e2bfd
commit 57c831442e

View File

@ -37,7 +37,7 @@ def slugify(value: str, allow_unicode: bool = False) -> str:
def safe_filename(directory: Path, value: str) -> str: def safe_filename(directory: Path, value: str) -> str:
"""Make a string safe to use as a filename.""" """Make a string safe to use as a filename."""
escaped_string = slugify(value) escaped_string = slugify(value)
max_name_length = os.pathconf(directory, "PC_NAME_MAX") max_name_length = os.pathconf(directory, "PC_NAME_MAX") if hasattr(os, "pathconf") else 256
return escaped_string[len(escaped_string) - max_name_length :] return escaped_string[len(escaped_string) - max_name_length :]