tarfile-write: Fix permissions when adding to archive.

Signed-off-by: ubi de feo <me@ubidefeo.com>
pull/799/head
ubi de feo 2024-02-05 08:18:19 +01:00 zatwierdzone przez Damien George
rodzic 56f514f569
commit 8058b2935b
2 zmienionych plików z 4 dodań i 3 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
metadata(description="Adds write (create/append) support to tarfile.", version="0.1.1")
metadata(description="Adds write (create/append) support to tarfile.", version="0.1.2")
require("tarfile")
package("tarfile")

Wyświetl plik

@ -67,7 +67,7 @@ def addfile(self, tarinfo, fileobj=None):
name += "/"
hdr = uctypes.struct(uctypes.addressof(buf), _TAR_HEADER, uctypes.LITTLE_ENDIAN)
hdr.name[:] = name.encode("utf-8")[:100]
hdr.mode[:] = b"%07o\0" % (tarinfo.mode & 0o7777)
hdr.mode[:] = b"%07o\0" % ((0o755 if tarinfo.isdir() else 0o644) & 0o7777)
hdr.uid[:] = b"%07o\0" % tarinfo.uid
hdr.gid[:] = b"%07o\0" % tarinfo.gid
hdr.size[:] = b"%011o\0" % size
@ -96,9 +96,10 @@ def addfile(self, tarinfo, fileobj=None):
def add(self, name, recursive=True):
from . import TarInfo
tarinfo = TarInfo(name)
try:
stat = os.stat(name)
res_name = (name + '/') if (stat[0] & 0xf000) == 0x4000 else name
tarinfo = TarInfo(res_name)
tarinfo.mode = stat[0]
tarinfo.uid = stat[4]
tarinfo.gid = stat[5]