Skip to content

Commit

Permalink
fix: extract zipfiles from Windows powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
fliiiix committed Mar 22, 2024
1 parent 898911e commit a0367d9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion docat/docat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit a0367d9

Please sign in to comment.