From a0367d9c7be8e7aafef766363dfc35450870d951 Mon Sep 17 00:00:00 2001 From: fliiiix Date: Fri, 22 Mar 2024 10:28:31 +0100 Subject: [PATCH] fix: extract zipfiles from Windows powershell --- docat/docat/utils.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docat/docat/utils.py b/docat/docat/utils.py index dc37f1e3a..bcacd28a3 100644 --- a/docat/docat/utils.py +++ b/docat/docat/utils.py @@ -6,7 +6,7 @@ import os import shutil from pathlib import Path -from zipfile import ZipFile +from zipfile import ZipFile, ZipInfo from docat.models import Project, ProjectDetail, Projects, ProjectVersion @@ -15,6 +15,25 @@ DB_PATH = "db.json" +def is_dir(self): + """Return True if this archive member is a directory.""" + if self.filename.endswith("/"): + return True + # The ZIP format specification requires to use forward slashes + # as the directory separator, but in practice some ZIP files + # created on Windows can use backward slashes. For compatibility + # with the extraction code which already handles this: + if os.path.altsep: + return self.filename.endswith((os.path.sep, os.path.altsep)) + return False + + +# Patch is_dir to allow windows zip files to be +# extracted correctly +# see: https://github.com/python/cpython/issues/117084 +ZipInfo.is_dir = is_dir # type: ignore[method-assign] + + def create_symlink(source, destination): """ Create a symlink from source to destination, if the