Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.build
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush Tiwari
slapos.recipe.build
Commits
e3e15b9f
Commit
e3e15b9f
authored
Mar 08, 2017
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
downloadunpacked: extract symlinks in a tar archive as symlinks.
parent
af85beec
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
1 deletion
+56
-1
slapos/recipe/downloadunpacked.py
slapos/recipe/downloadunpacked.py
+56
-1
No files found.
slapos/recipe/downloadunpacked.py
View file @
e3e15b9f
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
import
os
import
os
import
logging
import
logging
import
shutil
import
shutil
import
tarfile
import
zc.buildout
import
zc.buildout
import
tempfile
import
tempfile
import
setuptools
import
setuptools
...
@@ -80,7 +81,11 @@ class Recipe:
...
@@ -80,7 +81,11 @@ class Recipe:
md5sum
=
self
.
options
.
get
(
'md5sum'
))
md5sum
=
self
.
options
.
get
(
'md5sum'
))
extract_dir
=
tempfile
.
mkdtemp
(
self
.
name
)
extract_dir
=
tempfile
.
mkdtemp
(
self
.
name
)
self
.
logger
.
debug
(
'Created working directory %r'
%
extract_dir
)
self
.
logger
.
debug
(
'Created working directory %r'
%
extract_dir
)
try
:
patch_archive_util
()
setuptools
.
archive_util
.
unpack_archive
(
path
,
extract_dir
)
setuptools
.
archive_util
.
unpack_archive
(
path
,
extract_dir
)
finally
:
unpatch_archive_util
()
# Delete destination directory if exist
# Delete destination directory if exist
if
os
.
path
.
exists
(
self
.
destination
):
if
os
.
path
.
exists
(
self
.
destination
):
...
@@ -112,3 +117,53 @@ class Recipe:
...
@@ -112,3 +117,53 @@ class Recipe:
def
update
(
self
):
def
update
(
self
):
pass
pass
# Monkey patch to keep symlinks in tarfile
def
unpack_tarfile_patched
(
filename
,
extract_dir
,
progress_filter
=
setuptools
.
archive_util
.
default_filter
):
"""Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
by ``tarfile.open()``). See ``unpack_archive()`` for an explanation
of the `progress_filter` argument.
"""
try
:
tarobj
=
tarfile
.
open
(
filename
)
except
tarfile
.
TarError
:
raise
setuptools
.
archive_util
.
UnrecognizedFormat
(
"%s is not a compressed or uncompressed tar file"
%
(
filename
,)
)
with
setuptools
.
archive_util
.
contextlib
.
closing
(
tarobj
):
# don't do any chowning!
tarobj
.
chown
=
lambda
*
args
:
None
for
member
in
tarobj
:
name
=
member
.
name
# don't extract absolute paths or ones with .. in them
if
not
name
.
startswith
(
'/'
)
and
'..'
not
in
name
.
split
(
'/'
):
prelim_dst
=
os
.
path
.
join
(
extract_dir
,
*
name
.
split
(
'/'
))
if
member
is
not
None
and
(
member
.
isfile
()
or
member
.
isdir
()
or
member
.
islnk
()
or
member
.
issym
()):
final_dst
=
progress_filter
(
name
,
prelim_dst
)
if
final_dst
:
if
final_dst
.
endswith
(
os
.
sep
):
final_dst
=
final_dst
[:
-
1
]
try
:
# XXX Ugh
tarobj
.
_extract_member
(
member
,
final_dst
)
except
tarfile
.
ExtractError
:
# chown/chmod/mkfifo/mknode/makedev failed
pass
return
True
def
patch_archive_util
():
setuptools
.
archive_util
.
extraction_drivers
=
(
setuptools
.
archive_util
.
unpack_directory
,
setuptools
.
archive_util
.
unpack_zipfile
,
unpack_tarfile_patched
,
)
def
unpatch_archive_util
():
setuptools
.
archive_util
.
extraction_drivers
=
(
setuptools
.
archive_util
.
unpack_directory
,
setuptools
.
archive_util
.
unpack_zipfile
,
setuptools
.
archive_util
.
unpack_tarfile
,
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment