Skip to content

Commit 8058b29

Browse files
ubidefeodpgeorge
authored andcommitted
tarfile-write: Fix permissions when adding to archive.
Signed-off-by: ubi de feo <[email protected]>
1 parent 56f514f commit 8058b29

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(description="Adds write (create/append) support to tarfile.", version="0.1.1")
1+
metadata(description="Adds write (create/append) support to tarfile.", version="0.1.2")
22

33
require("tarfile")
44
package("tarfile")

python-stdlib/tarfile-write/tarfile/write.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def addfile(self, tarinfo, fileobj=None):
6767
name += "/"
6868
hdr = uctypes.struct(uctypes.addressof(buf), _TAR_HEADER, uctypes.LITTLE_ENDIAN)
6969
hdr.name[:] = name.encode("utf-8")[:100]
70-
hdr.mode[:] = b"%07o\0" % (tarinfo.mode & 0o7777)
70+
hdr.mode[:] = b"%07o\0" % ((0o755 if tarinfo.isdir() else 0o644) & 0o7777)
7171
hdr.uid[:] = b"%07o\0" % tarinfo.uid
7272
hdr.gid[:] = b"%07o\0" % tarinfo.gid
7373
hdr.size[:] = b"%011o\0" % size
@@ -96,9 +96,10 @@ def addfile(self, tarinfo, fileobj=None):
9696
def add(self, name, recursive=True):
9797
from . import TarInfo
9898

99-
tarinfo = TarInfo(name)
10099
try:
101100
stat = os.stat(name)
101+
res_name = (name + '/') if (stat[0] & 0xf000) == 0x4000 else name
102+
tarinfo = TarInfo(res_name)
102103
tarinfo.mode = stat[0]
103104
tarinfo.uid = stat[4]
104105
tarinfo.gid = stat[5]

0 commit comments

Comments
 (0)