Reputation: 4022
I am using tarfile
module to check the permission of the packages in my tar.gz file.
My problem are two folds.
Permission bits value are different from the value got from ls -l
command. From list
command, value is 755
. But I get 488
in my program. I use the below command function -
def checkAndExtratZipFile (value,packageElementInfoList):
try:
tar = tarfile.open(value,"r:gz")
for tarinfo in tar:
global elementType
# Populate all information about the element
name = tarinfo.name
size = tarinfo.size
perm = tarinfo.mode
if tarinfo.isdir():
eleType = elementType.Directory
elif tarinfo.issym():
eleType = elementType.SymbolicLink
else:
eleType = elementType.File
# Populate into list
packageElementInfoList.append(packageElementInfo(name,eleType,perm,size))
tar.close()
except:
print "Verification of package %s failed.\n Reason : Not able to read contents in the tar package." % value
sys.exit(1)
My system (working on SUSE Linux) will have packages to be verified which are created by SUSE/AIX and HP platform. So I need to verify packages built on AIX/HP/Linux platform on Linux Server.
The permission bits of AIX/HP package on Linux is very weird.A 755
permission bit is given as 33256
.
Any help is appreciated.
Upvotes: 2
Views: 2725
Reputation: 37899
You're seeing a base-10 representation of an octal number:
>>> oct(488)
'0750'
You need to check flags using attributes on the stat
module:
>>> tarinfo.mode
488
>>> tarinfo.mode & stat.S_IXGRP != 0
True
>>> tarinfo.mode & stat.S_IXOTH != 0
False
Upvotes: 10