Skip to content

Commit

Permalink
Implement preservation of of permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz committed Apr 20, 2021
1 parent 07e02eb commit 3c92702
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/zip_files/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re
from pathlib import Path
from string import ascii_letters
from zipfile import ZipFile
from zipfile import ZipFile, ZipInfo

import click

Expand Down Expand Up @@ -257,12 +257,19 @@ def zip_files(
exclude,
exclude_dotfiles,
relative_to=file.parent,
compression=compression,
)
logger.debug("Done")


def _add_to_zip(
zipfile, file, root_folder, exclude, exclude_dotfiles, relative_to
zipfile,
file,
root_folder,
exclude,
exclude_dotfiles,
relative_to,
compression,
):
"""Recursively add the `file` to the (open) `zipfile`."""
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -293,7 +300,9 @@ def _add_to_zip(
else:
raise TypeError("Invalid type for pattern %r" % pattern)
logger.debug("Adding %s to zip as %s", file, filename)
zipfile.writestr(str(filename), data)
zinfo = ZipInfo.from_file(file, arcname=str(filename))
zinfo.compress_type = compression
zipfile.writestr(zinfo, data)
elif file.is_dir():
directory = file
for file_in_dir in directory.iterdir():
Expand All @@ -304,4 +313,5 @@ def _add_to_zip(
exclude,
exclude_dotfiles,
relative_to,
compression,
)

0 comments on commit 3c92702

Please sign in to comment.