Skip to content

Commit 97cbaf7

Browse files
committed
Update pyarchivefile.py
1 parent 6fb1089 commit 97cbaf7

File tree

1 file changed

+89
-22
lines changed

1 file changed

+89
-22
lines changed

pyarchivefile.py

Lines changed: 89 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6918,7 +6918,7 @@ def AppendFilesWithContentFromTarFileToList(infile, extradata=[], jsondata={}, c
69186918
fblocks = 0
69196919
fflags = 0
69206920
ftype = 0
6921-
if(member.isreg()):
6921+
if(member.isreg() or member.isfile()):
69226922
ffullmode = member.mode + stat.S_IFREG
69236923
ftype = 0
69246924
elif(member.islnk()):
@@ -7123,9 +7123,13 @@ def AppendFilesWithContentFromZipFileToList(infile, extradata=[], jsondata={}, c
71237123
ftype = 0
71247124
if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
71257125
ftype = 5
7126+
elif ((hasattr(member, "symlink") and member.symlink())):
7127+
ftype = 2
71267128
else:
71277129
ftype = 0
71287130
flinkname = ""
7131+
if(ftype==2):
7132+
flinkname = zipfp.read(member.filename).decode("UTF-8")
71297133
fcurfid = format(int(curfid), 'x').lower()
71307134
fcurinode = format(int(curfid), 'x').lower()
71317135
curfid = curfid + 1
@@ -7151,6 +7155,10 @@ def AppendFilesWithContentFromZipFileToList(infile, extradata=[], jsondata={}, c
71517155
fmode = format(int(stat.S_IFDIR | 0x1ff), 'x').lower()
71527156
fchmode = stat.S_IMODE(int(stat.S_IFDIR | 0x1ff))
71537157
ftypemod = stat.S_IFMT(int(stat.S_IFDIR | 0x1ff))
7158+
elif ((hasattr(member, "symlink") and member.symlink()) or member.filename.endswith('/')):
7159+
fmode = format(int(stat.S_IFREG | 0x1b6), 'x').lower()
7160+
fchmode = stat.S_IMODE(int(stat.S_IFREG | 0x1b6))
7161+
ftypemod = stat.S_IFMT(int(stat.S_IFREG | 0x1b6))
71547162
else:
71557163
fmode = format(int(stat.S_IFREG | 0x1b6), 'x').lower()
71567164
fchmode = stat.S_IMODE(int(stat.S_IFREG | 0x1b6))
@@ -7159,6 +7167,17 @@ def AppendFilesWithContentFromZipFileToList(infile, extradata=[], jsondata={}, c
71597167
fwinattributes = format(int(zipinfo.external_attr & 0xFFFF), 'x').lower()
71607168
fmode = format(int((zipinfo.external_attr >> 16) & 0xFFFF), 'x').lower()
71617169
prefmode = int((zipinfo.external_attr >> 16) & 0xFFFF)
7170+
if(prefmode==0):
7171+
fmode = 0
7172+
prefmode = 0
7173+
else:
7174+
file_type = prefmode & 0xF000
7175+
if(file_type not in (stat.S_IFREG, stat.S_IFDIR, stat.S_IFLNK)):
7176+
fmode = 0
7177+
prefmode = 0
7178+
if((mode & 0x1FF) == 0):
7179+
fmode = 0
7180+
prefmode = 0
71627181
if (prefmode == 0):
71637182
if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
71647183
fmode = format(int(stat.S_IFDIR | 0x1ff), 'x').lower()
@@ -7605,7 +7624,10 @@ def AppendFilesWithContentFromSevenZipFileToList(infile, extradata=[], jsondata=
76057624
fpremode = int(stat.S_IFREG | 0x1b6)
76067625
elif(member.is_directory):
76077626
fpremode = int(stat.S_IFDIR | 0x1ff)
7608-
fwinattributes = format(int(0), 'x').lower()
7627+
try:
7628+
fwinattributes = format(int(member.attributes & 0xFFFF), 'x').lower()
7629+
except AttributeError:
7630+
fwinattributes = format(int(0), 'x').lower()
76097631
fcompression = ""
76107632
fcsize = format(int(0), 'x').lower()
76117633
flinkcount = 0
@@ -7641,6 +7663,13 @@ def AppendFilesWithContentFromSevenZipFileToList(infile, extradata=[], jsondata=
76417663
int(stat.S_IMODE(int(stat.S_IFREG | 0x1b6))), 'x').lower()
76427664
ftypemod = format(
76437665
int(stat.S_IFMT(int(stat.S_IFREG | 0x1b6))), 'x').lower()
7666+
try:
7667+
ffullmode = member.posix_mode
7668+
fmode = format(int(ffullmode), 'x').lower()
7669+
fchmode = format(int(stat.S_IMODE(ffullmode)), 'x').lower()
7670+
ftypemod = format(int(stat.S_IFMT(ffullmode)), 'x').lower()
7671+
except AttributeError:
7672+
pass
76447673
try:
76457674
fuid = format(int(os.getuid()), 'x').lower()
76467675
except (KeyError, AttributeError):
@@ -11643,7 +11672,7 @@ def TarFileListFiles(infile, formatspecs=__file_format_multi_dict__, verbose=Fal
1164311672
ffullmode = member.mode
1164411673
flinkcount = 0
1164511674
ftype = 0
11646-
if(member.isreg()):
11675+
if(member.isreg() or member.isfile()):
1164711676
ffullmode = member.mode + stat.S_IFREG
1164811677
ftype = 0
1164911678
elif(member.islnk()):
@@ -11734,35 +11763,59 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
1173411763
for member in sorted(zipfp.infolist(), key=lambda x: x.filename):
1173511764
zipinfo = zipfp.getinfo(member.filename)
1173611765
if(zipinfo.create_system == 0 or zipinfo.create_system == 10):
11737-
fwinattributes = int(zipinfo.external_attr)
11766+
fwinattributes = int(zipinfo.external_attr & 0xFFFF)
1173811767
if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
1173911768
fmode = int(stat.S_IFDIR | 0x1ff)
11740-
fchmode = int(stat.S_IMODE(int(stat.S_IFDIR | 0x1ff)))
11741-
ftypemod = int(stat.S_IFMT(int(stat.S_IFDIR | 0x1ff)))
11769+
fchmode = stat.S_IMODE(int(stat.S_IFDIR | 0x1ff))
11770+
ftypemod = stat.S_IFMT(int(stat.S_IFDIR | 0x1ff))
11771+
elif ((hasattr(member, "symlink") and member.symlink()) or member.filename.endswith('/')):
11772+
fmode = int(stat.S_IFREG | 0x1b6)
11773+
fchmode = stat.S_IMODE(int(stat.S_IFREG | 0x1b6))
11774+
ftypemod = stat.S_IFMT(int(stat.S_IFREG | 0x1b6))
1174211775
else:
1174311776
fmode = int(stat.S_IFREG | 0x1b6)
11744-
fchmode = int(stat.S_IMODE(fmode))
11745-
ftypemod = int(stat.S_IFMT(fmode))
11777+
fchmode = stat.S_IMODE(int(stat.S_IFREG | 0x1b6))
11778+
ftypemod = stat.S_IFMT(int(stat.S_IFREG | 0x1b6))
1174611779
elif(zipinfo.create_system == 3):
11747-
fwinattributes = int(0)
11748-
try:
11749-
fmode = int(zipinfo.external_attr)
11750-
fchmode = stat.S_IMODE(fmode)
11751-
ftypemod = stat.S_IFMT(fmode)
11752-
except OverflowError:
11753-
fmode = int(zipinfo.external_attr >> 16)
11754-
fchmode = stat.S_IMODE(fmode)
11755-
ftypemod = stat.S_IFMT(fmode)
11780+
fwinattributes = int(zipinfo.external_attr & 0xFFFF)
11781+
fmode = int((zipinfo.external_attr >> 16) & 0xFFFF)
11782+
prefmode = int((zipinfo.external_attr >> 16) & 0xFFFF)
11783+
if(prefmode==0):
11784+
fmode = 0
11785+
prefmode = 0
11786+
else:
11787+
file_type = prefmode & 0xF000
11788+
if(file_type not in (stat.S_IFREG, stat.S_IFDIR, stat.S_IFLNK)):
11789+
fmode = 0
11790+
prefmode = 0
11791+
if((mode & 0x1FF) == 0):
11792+
fmode = 0
11793+
prefmode = 0
11794+
if (prefmode == 0):
11795+
if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
11796+
fmode = int(stat.S_IFDIR | 0x1ff)
11797+
prefmode = int(stat.S_IFDIR | 0x1ff)
11798+
fchmode = stat.S_IMODE(prefmode)
11799+
ftypemod = stat.S_IFMT(prefmode)
11800+
else:
11801+
fmode = int(stat.S_IFREG | 0x1b6)
11802+
prefmode = int(stat.S_IFREG | 0x1b6)
11803+
fchmode = stat.S_IMODE(prefmode)
11804+
ftypemod = stat.S_IFMT(prefmode)
11805+
fchmode = stat.S_IMODE(prefmode)
11806+
ftypemod = stat.S_IFMT(prefmode)
1175611807
else:
11757-
fwinattributes = int(0)
11808+
fwinattributes = int(zipinfo.external_attr & 0xFFFF)
1175811809
if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
1175911810
fmode = int(stat.S_IFDIR | 0x1ff)
11760-
fchmode = int(stat.S_IMODE(int(stat.S_IFDIR | 0x1ff)))
11761-
ftypemod = int(stat.S_IFMT(int(stat.S_IFDIR | 0x1ff)))
11811+
prefmode = int(stat.S_IFDIR | 0x1ff)
11812+
fchmode = stat.S_IMODE(prefmode)
11813+
ftypemod = stat.S_IFMT(prefmode)
1176211814
else:
1176311815
fmode = int(stat.S_IFREG | 0x1b6)
11764-
fchmode = int(stat.S_IMODE(fmode))
11765-
ftypemod = int(stat.S_IFMT(fmode))
11816+
prefmode = int(stat.S_IFREG | 0x1b6)
11817+
fchmode = stat.S_IMODE(prefmode)
11818+
ftypemod = stat.S_IFMT(prefmode)
1176611819
returnval.update({lcfi: member.filename})
1176711820
if(not verbose):
1176811821
VerbosePrintOut(member.filename)
@@ -11776,10 +11829,17 @@ def ZipFileListFiles(infile, verbose=False, returnfp=False):
1177611829
if ((hasattr(member, "is_dir") and member.is_dir()) or member.filename.endswith('/')):
1177711830
ftype = 5
1177811831
permissionstr = "d" + permissionstr
11832+
elif ((hasattr(member, "symlink") and member.symlink())):
11833+
ftype = 2
11834+
permissionstr = "l" + permissionstr
1177911835
else:
1178011836
ftype = 0
1178111837
permissionstr = "-" + permissionstr
1178211838
printfname = member.filename
11839+
if(ftype==2):
11840+
flinkname = zipfp.read(member.filename).decode("UTF-8")
11841+
if(ftype==2):
11842+
printfname = member.filename + " -> " + flinkname
1178311843
try:
1178411844
fuid = int(os.getuid())
1178511845
except (KeyError, AttributeError):
@@ -11995,6 +12055,13 @@ def SevenZipFileListFiles(infile, verbose=False, returnfp=False):
1199512055
fmode = int(stat.S_IFLNK | 0x1b6)
1199612056
fchmode = int(stat.S_IMODE(int(stat.S_IFLNK | 0x1b6)))
1199712057
ftypemod = int(stat.S_IFMT(int(stat.S_IFLNK | 0x1b6)))
12058+
try:
12059+
ffullmode = member.posix_mode
12060+
fmode = format(int(ffullmode), 'x').lower()
12061+
fchmode = format(int(stat.S_IMODE(ffullmode)), 'x').lower()
12062+
ftypemod = format(int(stat.S_IFMT(ffullmode)), 'x').lower()
12063+
except AttributeError:
12064+
pass
1199812065
returnval.update({lcfi: member.filename})
1199912066
if(not verbose):
1200012067
VerbosePrintOut(member.filename)

0 commit comments

Comments
 (0)