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

Proposed by Sergio Schvezov
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 235
Merged at revision: 234
Proposed branch: lp:~sergiusens/snapcraft/1500505
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 106 lines (+44/-4)
4 files modified
plugins/jdk.yaml (+2/-0)
snapcraft/repo.py (+37/-3)
snapcraft/sources.py (+1/-1)
snapcraft/tests/test_repo.py (+4/-0)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1500505
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+273826@code.launchpad.net

Commit message

Copy links to packages we did not download and also untarring not world writable.

Description of the change

I'm not sure I like this, if you look at the bug, most of the dangling symlinks are from libraries provided by libc6.

The one I haven't figured out how it go onto my system is the target for /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/security/cacerts as no package owns it.

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) :
review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

The attempt to merge lp:~sergiusens/snapcraft/1500505 into lp:snapcraft failed. Below is the output from the failed tests.

name: # the name of the snap
version: # the version of the snap
# The vendor for the snap (replace 'Vendor <email address hidden>')
vendor: Vendor <email address hidden>
summary: # 79 char long summary
description: # A longer description for the snap
icon: # A path to an icon for the package
cp --preserve=all -R zzz /tmp/tmpfqjb5zom/parts/copy/install/zzz
cp --preserve=all -R src /tmp/tmp4yykp3c4/parts/copy/install/dst
cp --preserve=all -R src /tmp/tmpo047wt4b/parts/copy/install/dir/dst

...................................Warning: unable to find "test_relexepath" in the path
............../tmp/tmp71nc0tyw/abs-to-b will be a dangling symlink
F.....................................................
======================================================================
FAIL: test_fix_symlinks (snapcraft.tests.test_repo.UbuntuTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.lg1XOE/snapcraft/tests/test_repo.py", line 84, in test_fix_symlinks
    self.assertEqual(os.readlink(tempdir + '/abs-to-b'), '/b')
AssertionError: 'b' != '/b'
- b
+ /b
? +

----------------------------------------------------------------------
Ran 103 tests in 2.933s

FAILED (failures=1)

lp:~sergiusens/snapcraft/1500505 updated
235. By Sergio Schvezov

fixing logic

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/jdk.yaml'
2--- plugins/jdk.yaml 2015-07-20 21:11:39 +0000
3+++ plugins/jdk.yaml 2015-10-08 19:26:03 +0000
4@@ -0,0 +1,2 @@
5+build-packages:
6+ - ca-certificates-java
7
8=== modified file 'snapcraft/repo.py'
9--- snapcraft/repo.py 2015-10-05 16:56:10 +0000
10+++ snapcraft/repo.py 2015-10-08 19:26:03 +0000
11@@ -17,9 +17,11 @@
12 import apt
13 import glob
14 import itertools
15+import logging
16 import os
17 import platform
18 import string
19+import shutil
20 import subprocess
21 import urllib
22 import urllib.request
23@@ -28,6 +30,8 @@
24
25 import snapcraft.common
26
27+logger = logging.getLogger(__name__)
28+
29 _DEFAULT_SOURCES = \
30 '''deb http://${prefix}.ubuntu.com/${suffix}/ ${release} main restricted
31 deb http://${prefix}.ubuntu.com/${suffix}/ ${release}-updates main restricted
32@@ -232,6 +236,36 @@
33 path = os.path.join(root, entry)
34 if os.path.islink(path) and os.path.isabs(os.readlink(path)):
35 target = os.path.join(debdir, os.readlink(path)[1:])
36- if os.path.exists(target):
37- os.remove(path)
38- os.symlink(os.path.relpath(target, root), path)
39+ if _skip_link(os.readlink(path)):
40+ logger.debug('Skipping {}'.format(target))
41+ continue
42+ if not os.path.exists(target):
43+ if not _try_copy_local(path, target):
44+ continue
45+ os.remove(path)
46+ os.symlink(os.path.relpath(target, root), path)
47+
48+
49+_skip_list = None
50+
51+
52+def _skip_link(target):
53+ global _skip_list
54+ if not _skip_list:
55+ output = snapcraft.common.run_output(['dpkg', '-L', 'libc6']).split()
56+ _skip_list = [i for i in output if 'lib' in i]
57+
58+ return target in _skip_list
59+
60+
61+def _try_copy_local(path, target):
62+ real_path = os.path.realpath(path)
63+ if os.path.exists(real_path):
64+ logger.warning(
65+ 'Copying needed target link from the system {}'.format(real_path))
66+ shutil.copyfile(os.readlink(path), target)
67+ return True
68+ else:
69+ logger.warning(
70+ '{} will be a dangling symlink'.format(path))
71+ return False
72
73=== modified file 'snapcraft/sources.py'
74--- snapcraft/sources.py 2015-10-05 16:56:10 +0000
75+++ snapcraft/sources.py 2015-10-08 19:26:03 +0000
76@@ -193,7 +193,7 @@
77 m.name = re.sub(r'^(\.{0,2}/)*', r'', m.name)
78 # We mask all files to be writable to be able to easily
79 # extract on top.
80- m.mode = m.mode | 0o222
81+ m.mode = m.mode | 0o200
82 yield m
83
84 tar.extractall(members=filter_members(tar), path=dst)
85
86=== modified file 'snapcraft/tests/test_repo.py'
87--- snapcraft/tests/test_repo.py 2015-10-05 16:56:10 +0000
88+++ snapcraft/tests/test_repo.py 2015-10-08 19:26:03 +0000
89@@ -14,6 +14,8 @@
90 # You should have received a copy of the GNU General Public License
91 # along with this program. If not, see <http://www.gnu.org/licenses/>.
92
93+import fixtures
94+import logging
95 import os
96 import tempfile
97 import unittest.mock
98@@ -64,6 +66,8 @@
99 self.assertFalse(mock_cc.called)
100
101 def test_fix_symlinks(self):
102+ fake_logger = fixtures.FakeLogger(level=logging.ERROR)
103+ self.useFixture(fake_logger)
104 tempdirObj = tempfile.TemporaryDirectory()
105 self.addCleanup(tempdirObj.cleanup)
106 tempdir = tempdirObj.name

Subscribers

People subscribed via source and target branches