Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
26d9a85b
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
26d9a85b
编写于
6月 30, 2016
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'zip-symlinks3'
上级
ed66d9ad
79f259e5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
3 deletion
+74
-3
avocado/utils/archive.py
avocado/utils/archive.py
+31
-2
selftests/.data/test_archive__symlinks.zip
selftests/.data/test_archive__symlinks.zip
+0
-0
selftests/unit/test_archive.py
selftests/unit/test_archive.py
+43
-1
未找到文件。
avocado/utils/archive.py
浏览文件 @
26d9a85b
...
...
@@ -11,16 +11,21 @@
#
# Copyright: Red Hat Inc. 2014
# Author: Ruda Moura <rmoura@redhat.com>
"""
Module to help extract and create compressed archives.
"""
import
logging
import
os
import
platform
import
stat
import
tarfile
import
zipfile
LOG
=
logging
.
getLogger
(
__name__
)
try
:
import
lzma
LZMA_CAPABLE
=
True
...
...
@@ -159,6 +164,30 @@ class ArchiveFile(object):
:param path: destination path.
"""
self
.
_engine
.
extractall
(
path
)
if
self
.
is_zip
:
self
.
_update_zip_extra_attrs
(
path
)
def
_update_zip_extra_attrs
(
self
,
dst_dir
):
if
platform
.
system
()
!=
"Linux"
:
LOG
.
warn
(
"Attr handling in zip files only supported on Linux."
)
return
# Walk all files and re-create files as symlinks
for
path
,
info
in
self
.
_engine
.
NameToInfo
.
iteritems
():
dst
=
os
.
path
.
join
(
dst_dir
,
path
)
if
not
os
.
path
.
exists
(
dst
):
LOG
.
warn
(
"Paths in this zip file are stored in unsupported "
"format, not updating the attributes. (%s)"
,
msg
)
return
attr
=
info
.
external_attr
>>
16
if
attr
&
stat
.
S_IFLNK
==
stat
.
S_IFLNK
:
dst
=
os
.
path
.
join
(
dst_dir
,
path
)
src
=
open
(
dst
,
'r'
).
read
()
os
.
remove
(
dst
)
os
.
symlink
(
src
,
dst
)
continue
# Don't override any other attributes on links
mode
=
attr
&
511
# Mask only permissions
if
mode
and
mode
!=
436
:
# If mode is stored and is not default
os
.
chmod
(
dst
,
mode
)
def
close
(
self
):
"""
...
...
selftests/.data/test_archive__symlinks.zip
0 → 100644
浏览文件 @
26d9a85b
文件已添加
selftests/unit/test_archive.py
浏览文件 @
26d9a85b
...
...
@@ -93,8 +93,50 @@ class ArchiveTest(unittest.TestCase):
def
test_tbz2_2_file
(
self
):
self
.
compress_and_check_file
(
'.tbz2'
)
def
test_zip_extra_attrs
(
self
):
"""
Check that utils.archive reflects extra attrs of file like symlinks
and file permissions.
"""
def
get_path
(
*
args
):
""" Get path with decompressdir prefix """
return
os
.
path
.
join
(
self
.
decompressdir
,
*
args
)
# File types
zip_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
os
.
path
.
pardir
,
".data"
,
"test_archive__symlinks.zip"
))
archive
.
uncompress
(
zip_path
,
self
.
decompressdir
)
self
.
assertTrue
(
os
.
path
.
islink
(
get_path
(
"link_to_dir"
)))
self
.
assertTrue
(
os
.
path
.
islink
(
get_path
(
"link_to_file"
)))
self
.
assertTrue
(
os
.
path
.
islink
(
get_path
(
"link_to_file2"
)))
self
.
assertTrue
(
os
.
path
.
islink
(
get_path
(
"dir"
,
"2nd_link_to_file"
)))
self
.
assertTrue
(
os
.
path
.
islink
(
get_path
(
"dir"
,
"link_to_link_to_file2"
)))
self
.
assertTrue
(
os
.
path
.
islink
(
get_path
(
"dir"
,
"2nd_link_to_file"
)))
self
.
assertTrue
(
os
.
path
.
islink
(
get_path
(
"link_to_dir"
,
"2nd_link_to_file"
)))
self
.
assertTrue
(
os
.
path
.
isfile
(
get_path
(
"file"
)))
self
.
assertTrue
(
os
.
path
.
isfile
(
get_path
(
"dir"
,
"file2"
)))
self
.
assertTrue
(
os
.
path
.
isfile
(
get_path
(
"link_to_dir"
,
"file2"
)))
act
=
os
.
path
.
realpath
(
get_path
(
"link_to_dir"
,
"link_to_link_to_file2"
))
exp
=
get_path
(
"dir"
,
"file2"
)
self
.
assertEqual
(
act
,
exp
)
self
.
assertEqual
(
os
.
path
.
realpath
(
get_path
(
"link_to_dir"
)),
get_path
(
"dir"
))
# File permissions
self
.
assertEqual
(
os
.
stat
(
get_path
(
"dir"
,
"file2"
)).
st_mode
&
0o777
,
0o664
)
self
.
assertEqual
(
os
.
stat
(
get_path
(
"file"
)).
st_mode
&
0o777
,
0o753
)
self
.
assertEqual
(
os
.
stat
(
get_path
(
"dir"
)).
st_mode
&
0o777
,
0o775
)
self
.
assertEqual
(
os
.
stat
(
get_path
(
"link_to_file2"
)).
st_mode
&
0o777
,
0o664
)
self
.
assertEqual
(
os
.
stat
(
get_path
(
"link_to_dir"
)).
st_mode
&
0o777
,
0o775
)
self
.
assertEqual
(
os
.
stat
(
get_path
(
"link_to_file"
)).
st_mode
&
0o777
,
0o753
)
def
tearDown
(
self
):
pass
try
:
shutil
.
rmtree
(
self
.
basedir
)
except
OSError
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录