我正在使用tarfilemodule来检查tar.gz文件中包的权限.我的问题有两个问题.
权限位值与从ls -l命令获得的值不同.从list命令来看,价值是755.但是我进入488了我的计划.我用下面的命令功能 -
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)
Run Code Online (Sandbox Code Playgroud)
我的系统(在SUSE Linux上工作)将包含要验证的包,这些包由SUSE/AIX和HP平台创建.所以我需要在Linux Server上验证构建在AIX/HP/Linux平台上的软件包.Linux上的AIX/HP软件包的755权限位非常奇怪.权限位给出为33256.
任何帮助表示赞赏.
您正在看到八进制数的基数10表示:
>>> oct(488)
'0750'
Run Code Online (Sandbox Code Playgroud)
您需要使用stat模块上的属性检查标志:
>>> tarinfo.mode
488
>>> tarinfo.mode & stat.S_IXGRP != 0
True
>>> tarinfo.mode & stat.S_IXOTH != 0
False
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1709 次 |
| 最近记录: |