handle files with "bad" names

This commit is contained in:
boyska 2024-11-21 15:49:57 +01:00
parent 15eeeccb4b
commit 583113c846

View file

@ -2,6 +2,7 @@
import datetime
import sys
import re
import json
from base64 import b64encode
from pathlib import Path
@ -99,7 +100,11 @@ class ArchiveBackend:
return False
def reserve(self, filename: Path) -> str:
bucketbase = filename.name.rsplit(".", maxsplit=1)[0].replace(".", "_")
bucketbase = re.sub(
r"""[^a-zA-Z0-9_.-]""", # based on what the archive.org documentation says
"_",
filename.name.rsplit(".", maxsplit=1)[0]
)
if not bucketbase.startswith(f"{self.bucketprefix}-"):
bucketbase = f"{self.bucketprefix}-" + bucketbase
bucketname = bucketbase