Merge lp:~chipaca/snappy/check-namespaces-on-sideload into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by John Lenton on 2015-04-21
Status: Merged
Approved by: Michael Vogt on 2015-04-21
Approved revision: 405
Merged at revision: 405
Proposed branch: lp:~chipaca/snappy/check-namespaces-on-sideload
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~chipaca/snappy/core-fmk-back-in-search
Diff against target: 120 lines (+69/-1)
4 files modified
snappy/click.go (+4/-0)
snappy/click_test.go (+14/-1)
snappy/snapp.go (+15/-0)
snappy/snapp_test.go (+36/-0)
To merge this branch: bzr merge lp:~chipaca/snappy/check-namespaces-on-sideload
Reviewer Review Type Date Requested Status
Michael Vogt 2015-04-21 Approve on 2015-04-21
Review via email: mp+256904@code.launchpad.net

Commit Message

don't let you sideload something you already have installed

To post a comment you must log in.
Michael Vogt (mvo) wrote :

LTGM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy/click.go'
2--- snappy/click.go 2015-04-21 10:25:14 +0000
3+++ snappy/click.go 2015-04-21 10:25:14 +0000
4@@ -866,6 +866,10 @@
5 return "", err
6 }
7
8+ if err := m.checkForPackageInstalled(namespace); err != nil {
9+ return "", err
10+ }
11+
12 if err := m.checkForNameClashes(); err != nil {
13 return "", err
14 }
15
16=== modified file 'snappy/click_test.go'
17--- snappy/click_test.go 2015-04-21 10:25:14 +0000
18+++ snappy/click_test.go 2015-04-21 10:25:14 +0000
19@@ -170,7 +170,7 @@
20 c.Assert(err, NotNil)
21 }
22
23-func (s *SnapTestSuite) TestLocalSnapInstall(c *C) {
24+func (s *SnapTestSuite) testLocalSnapInstall(c *C) string {
25 snapFile := makeTestSnapPackage(c, "")
26 name, err := installClick(snapFile, 0, nil, testNamespace)
27 c.Assert(err, IsNil)
28@@ -194,6 +194,19 @@
29 snap, err := NewInstalledSnapPart(filepath.Join(baseDir, "meta", "package.yaml"), testNamespace)
30 c.Assert(err, IsNil)
31 c.Assert(snap.Hash(), Not(Equals), "")
32+
33+ return snapFile
34+}
35+
36+func (s *SnapTestSuite) TestLocalSnapInstall(c *C) {
37+ s.testLocalSnapInstall(c)
38+}
39+
40+func (s *SnapTestSuite) TestLocalSnapInstallFailsAlreadyInstalled(c *C) {
41+ snapFile := s.testLocalSnapInstall(c)
42+
43+ _, err := installClick(snapFile, 0, nil, "namespaceother")
44+ c.Assert(err, Equals, ErrPackageNameAlreadyInstalled)
45 }
46
47 func (s *SnapTestSuite) TestLocalSnapInstallDebsigVerifyFails(c *C) {
48
49=== modified file 'snappy/snapp.go'
50--- snappy/snapp.go 2015-04-21 10:25:14 +0000
51+++ snappy/snapp.go 2015-04-21 10:25:14 +0000
52@@ -326,6 +326,21 @@
53 return nil
54 }
55
56+func (m *packageYaml) checkForPackageInstalled(namespace string) error {
57+ part := ActiveSnapByName(m.Name)
58+ if part == nil {
59+ return nil
60+ }
61+
62+ if m.Type != SnapTypeFramework {
63+ if part.Namespace() != namespace {
64+ return ErrPackageNameAlreadyInstalled
65+ }
66+ }
67+
68+ return nil
69+}
70+
71 func addCoreFmk(fmks []string) []string {
72 fmkCore := false
73 for _, a := range fmks {
74
75=== modified file 'snappy/snapp_test.go'
76--- snappy/snapp_test.go 2015-04-21 00:41:51 +0000
77+++ snappy/snapp_test.go 2015-04-21 10:25:14 +0000
78@@ -973,6 +973,42 @@
79 c.Assert(err, Equals, ErrInvalidFrameworkSpecInYaml)
80 }
81
82+func (s *SnapTestSuite) TestDetectsAlreadyInstalled(c *C) {
83+ data := "name: afoo\nversion: 1"
84+ yamlPath, err := makeInstalledMockSnap(s.tempdir, data)
85+ c.Assert(err, IsNil)
86+ c.Assert(makeSnapActive(yamlPath), IsNil)
87+
88+ yaml, err := parsePackageYamlData([]byte(data))
89+ c.Assert(err, IsNil)
90+ c.Check(yaml.checkForPackageInstalled("otherns"), Equals, ErrPackageNameAlreadyInstalled)
91+}
92+
93+func (s *SnapTestSuite) TestIgnoresAlreadyInstalledSameNamespace(c *C) {
94+ // XXX: should this be allowed? right now it is (=> you can re-sideload the same version of your apps)
95+ // (remote snaps are stopped before clickInstall gets to run)
96+
97+ data := "name: afoo\nversion: 1"
98+ yamlPath, err := makeInstalledMockSnap(s.tempdir, data)
99+ c.Assert(err, IsNil)
100+ c.Assert(makeSnapActive(yamlPath), IsNil)
101+
102+ yaml, err := parsePackageYamlData([]byte(data))
103+ c.Assert(err, IsNil)
104+ c.Check(yaml.checkForPackageInstalled(testNamespace), IsNil)
105+}
106+
107+func (s *SnapTestSuite) TestIgnoresAlreadyInstalledFrameworks(c *C) {
108+ data := "name: afoo\nversion: 1\ntype: framework"
109+ yamlPath, err := makeInstalledMockSnap(s.tempdir, data)
110+ c.Assert(err, IsNil)
111+ c.Assert(makeSnapActive(yamlPath), IsNil)
112+
113+ yaml, err := parsePackageYamlData([]byte(data))
114+ c.Assert(err, IsNil)
115+ c.Check(yaml.checkForPackageInstalled("otherns"), IsNil)
116+}
117+
118 func (s *SnapTestSuite) TestDetectsNameClash(c *C) {
119 data := []byte(`name: afoo
120 version: 1.0

Subscribers

People subscribed via source and target branches