Skip to content

Commit 104d1f1

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

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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)