From 639389e38fc42e54f9d4dcfb5efe88349940d48c Mon Sep 17 00:00:00 2001 From: yrriban Date: Sun, 2 Aug 2026 13:58:01 -0400 Subject: [PATCH] Normalize wads arriving in zips wrapping dirs. Most wads put all the files directly in the top level of the zip; some instead include a top level directory and put everything in that. We create our own directory to extract into to avoid polluting the PWAD directory, and then in the latter case move everything up a level and then remove the wrapping directory. --- doomcc/fetch.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doomcc/fetch.py b/doomcc/fetch.py index 3e5e411..9d2417c 100644 --- a/doomcc/fetch.py +++ b/doomcc/fetch.py @@ -29,9 +29,16 @@ class Fetch(doomcc.config.Base): ) wad = reply["content"]["filename"][0:-4] + pwadpath = self.pwads.joinpath(wad) with urllib.request.urlopen(rpath) as response: z = zipfile.ZipFile(io.BytesIO(response.read())) - z.extractall(path=self.pwads.joinpath(wad)) + z.extractall(path=pwadpath) + + contents = list(pwadpath.glob('*')) + if len(contents) == 1 and contents[0].is_dir(): + for wc in contents[0].glob('*'): + wc.rename(pwadpath.joinpath(wc.name)) + contents[0].rmdir() # TODO: explicit error handling. Let users choose when >1 result. def search_idgames(self, wad):