Merge lp:~sergiusens/snapcraft/1500728 into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 214
Merged at revision: 213
Proposed branch: lp:~sergiusens/snapcraft/1500728
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 74 lines (+18/-1)
3 files modified
integration-tests/data/simple-tar/snapcraft.yaml (+3/-0)
integration-tests/units/jobs.pxu (+3/-0)
snapcraft/sources.py (+12/-1)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1500728
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve
Michael Vogt (community) Approve
Review via email: mp+272697@code.launchpad.net

Commit message

Mask tar files so they are writable and set an extraction parameter to start with a clean build dir

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Looks great! One minor comment.

review: Approve
lp:~sergiusens/snapcraft/1500728 updated
214. By Sergio Schvezov

Added a comment about masking

Revision history for this message
Sergio Schvezov (sergiusens) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'integration-tests/data/simple-tar/readonly-files.tar.gz'
2Binary files integration-tests/data/simple-tar/readonly-files.tar.gz 1970-01-01 00:00:00 +0000 and integration-tests/data/simple-tar/readonly-files.tar.gz 2015-09-29 08:12:12 +0000 differ
3=== modified file 'integration-tests/data/simple-tar/snapcraft.yaml'
4--- integration-tests/data/simple-tar/snapcraft.yaml 2015-09-08 11:48:30 +0000
5+++ integration-tests/data/simple-tar/snapcraft.yaml 2015-09-29 08:12:12 +0000
6@@ -27,6 +27,9 @@
7 evil-slash:
8 type: tar-content
9 source: evil-slash.tar.gz
10+ readonly-files:
11+ type: tar-content
12+ source: readonly-files.tar.gz
13 project:
14 type: make-project
15 source: project.tar.xz
16
17=== modified file 'integration-tests/units/jobs.pxu'
18--- integration-tests/units/jobs.pxu 2015-09-23 13:42:57 +0000
19+++ integration-tests/units/jobs.pxu 2015-09-29 08:12:12 +0000
20@@ -93,7 +93,10 @@
21 test -e stage/notopdir
22 test -e stage/parent
23 test -e stage/slash
24+ test -e stage/readonly_file
25 test "$(./stage/bin/test)" = "tarproject"
26+ # Regression test for https://bugs.launchpad.net/snapcraft/+bug/1500728
27+ ${SNAPCRAFT} pull --force
28 flags: simple has-leftovers
29
30 id: snapcraft/normal/pypi-config
31
32=== modified file 'snapcraft/sources.py'
33--- snapcraft/sources.py 2015-09-15 05:17:14 +0000
34+++ snapcraft/sources.py 2015-09-29 08:12:12 +0000
35@@ -17,6 +17,7 @@
36 import logging
37 import os
38 import os.path
39+import shutil
40 import tarfile
41 import re
42
43@@ -130,13 +131,20 @@
44 else:
45 return True
46
47- def provision(self, dst):
48+ def provision(self, dst, clean_target=True):
49 # TODO add unit tests.
50 if snapcraft.common.isurl(self.source):
51 tarball = os.path.join(self.source_dir, os.path.basename(self.source))
52 else:
53 tarball = os.path.abspath(self.source)
54
55+ if clean_target:
56+ shutil.rmtree(dst)
57+ os.makedirs(dst)
58+
59+ return self._extract(tarball, dst)
60+
61+ def _extract(self, tarball, dst):
62 with tarfile.open(tarball) as tar:
63 def filter_members(tar):
64 """Filters members and member names:
65@@ -163,6 +171,9 @@
66 m.name = m.name[len(common + "/"):]
67 # strip leading "/", "./" or "../" as many times as needed
68 m.name = re.sub(r'^(\.{0,2}/)*', r'', m.name)
69+ # We mask all files to be writable to be able to easily
70+ # extract on top.
71+ m.mode = m.mode | 0o222
72 yield m
73
74 tar.extractall(members=filter_members(tar), path=dst)

Subscribers

People subscribed via source and target branches