Skip to content

Commit 3092362

Browse files
Raphael DussinRaphael Dussin
authored andcommitted
use zipinfo to fix permission
1 parent be29d36 commit 3092362

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

docs/release.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Release notes
44
Upcoming Release
55
----------------
66

7+
* Add intermediate step (using ``zipfile.ZipInfo`` object) to write
8+
inside ``ZipStore`` to solve too restrictive permission issue.
9+
By :user:`Raphael Dussin <raphaeldussin`; :issue:`505`.
10+
711
* Add key normalization option for ``DirectoryStore``, ``NestedDirectoryStore``,
812
``TempStore``, and ``N5Store``.
913
By :user:`James Bourbeau <jrbourbeau>`; :issue:`459`.
@@ -21,7 +25,7 @@ Upcoming Release
2125
* Upgrade dependencies in the test matrices and resolve a
2226
compatibility issue with testing against the Azure Storage
2327
Emulator. By :user:`alimanfoo`; :issue:`468`, :issue:`467`.
24-
28+
2529
* Do not rename Blosc parameters in n5 backend and add `blocksize` parameter,
2630
compatible with n5-blosc. By :user:`axtimwalde`, :issue:`485`.
2731

@@ -94,7 +98,7 @@ Enhancements
9498
~~~~~~~~~~~~
9599

96100
* New storage backend, backed by Azure Blob Storage, class :class:`zarr.storage.ABSStore`.
97-
All data is stored as block blobs. By :user:`Shikhar Goenka <shikarsg>`,
101+
All data is stored as block blobs. By :user:`Shikhar Goenka <shikarsg>`,
98102
:user:`Tim Crone <tjcrone>` and :user:`Zain Patel <mzjp2>`; :issue:`345`.
99103

100104
* Add "consolidated" metadata as an experimental feature: use

zarr/storage.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from pickle import PicklingError
3434
from threading import Lock, RLock
3535
import uuid
36+
import time
3637

3738
from numcodecs.compat import ensure_bytes, ensure_contiguous_ndarray
3839
from numcodecs.registry import codec_registry
@@ -1254,7 +1255,22 @@ def __setitem__(self, key, value):
12541255
err_read_only()
12551256
value = ensure_contiguous_ndarray(value)
12561257
with self.mutex:
1257-
self.zf.writestr(key, value)
1258+
# writestr(key, value) writes with default permissions from
1259+
# zipfile (600) that are too restrictive, build ZipInfo for
1260+
# the key to work around limitation
1261+
keyinfo = zipfile.ZipInfo(filename=key,
1262+
date_time=time.localtime(time.time())[:6])
1263+
keyinfo.compress_type = self.compression
1264+
if keyinfo.filename[-1] == os.sep:
1265+
keyinfo.external_attr = 0o40775 << 16 # drwxrwxr-x
1266+
keyinfo.external_attr |= 0x10 # MS-DOS directory flag
1267+
else:
1268+
keyinfo.external_attr = 0o644 << 16 # ?rw-r--r--
1269+
1270+
if isinstance(value, str):
1271+
value = value.encode("utf-8")
1272+
1273+
self.zf.writestr(keyinfo, value)
12581274

12591275
def __delitem__(self, key):
12601276
raise NotImplementedError

0 commit comments

Comments
 (0)