Merge lp:~sergiusens/snappy/YouShallNotPassBeforeEither into lp:~snappy-dev/snappy/15.04-deprecated

Proposed by Sergio Schvezov on 2015-06-04
Status: Merged
Approved by: John Lenton on 2015-06-04
Approved revision: 450
Merged at revision: 450
Proposed branch: lp:~sergiusens/snappy/YouShallNotPassBeforeEither
Merge into: lp:~snappy-dev/snappy/15.04-deprecated
Diff against target: 127 lines (+60/-0)
5 files modified
helpers/helpers.go (+14/-0)
helpers/helpers_test.go (+12/-0)
snappy/click.go (+5/-0)
snappy/errors.go (+12/-0)
snappy/snapp_test.go (+17/-0)
To merge this branch: bzr merge lp:~sergiusens/snappy/YouShallNotPassBeforeEither
Reviewer Review Type Date Requested Status
John Lenton 2015-06-04 Approve on 2015-06-04
Review via email: mp+261097@code.launchpad.net

This proposal supersedes a proposal from 2015-06-04.

Commit Message

Don't allow installation of packages with unsupported architectures (backported from trunk with bzr merge -c 484 from trunk)

To post a comment you must log in.
450. By Sergio Schvezov on 2015-06-04

Don't allow installation of packages with unsupported architectures (backported from trunk with bzr merge -c 484 from trunk)

John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'helpers/helpers.go'
2--- helpers/helpers.go 2015-06-03 19:34:38 +0000
3+++ helpers/helpers.go 2015-06-04 15:01:05 +0000
4@@ -177,6 +177,20 @@
5 }
6 }
7
8+// IsSupportedArchitecture returns true if the system architecture is in the
9+// list of architectures.
10+func IsSupportedArchitecture(architectures []string) bool {
11+ systemArch := UbuntuArchitecture()
12+
13+ for _, arch := range architectures {
14+ if arch == "all" || arch == systemArch {
15+ return true
16+ }
17+ }
18+
19+ return false
20+}
21+
22 // EnsureDir ensures that the given directory exists and if
23 // not creates it with the given permissions.
24 func EnsureDir(dir string, perm os.FileMode) (err error) {
25
26=== modified file 'helpers/helpers_test.go'
27--- helpers/helpers_test.go 2015-05-29 13:52:33 +0000
28+++ helpers/helpers_test.go 2015-06-04 15:01:05 +0000
29@@ -96,6 +96,18 @@
30 c.Check(UbuntuArchitecture(), Equals, "i386")
31 }
32
33+func (ts *HTestSuite) TestSupportedArchitectures(c *C) {
34+ goarch = "arm"
35+ c.Check(IsSupportedArchitecture([]string{"all"}), Equals, true)
36+ c.Check(IsSupportedArchitecture([]string{"amd64", "armhf", "powerpc"}), Equals, true)
37+ c.Check(IsSupportedArchitecture([]string{"armhf"}), Equals, true)
38+ c.Check(IsSupportedArchitecture([]string{"amd64", "powerpc"}), Equals, false)
39+
40+ goarch = "amd64"
41+ c.Check(IsSupportedArchitecture([]string{"amd64", "armhf", "powerpc"}), Equals, true)
42+ c.Check(IsSupportedArchitecture([]string{"powerpc"}), Equals, false)
43+}
44+
45 func (ts *HTestSuite) TestChdir(c *C) {
46 tmpdir := c.MkDir()
47
48
49=== modified file 'snappy/click.go'
50--- snappy/click.go 2015-06-03 19:34:38 +0000
51+++ snappy/click.go 2015-06-04 15:01:05 +0000
52@@ -904,6 +904,11 @@
53 return "", err
54 }
55
56+ // verify we have a valid architecture
57+ if !helpers.IsSupportedArchitecture(m.Architectures) {
58+ return "", &ErrArchitectureNotSupported{m.Architectures}
59+ }
60+
61 if err := m.checkForNameClashes(); err != nil {
62 return "", err
63 }
64
65=== modified file 'snappy/errors.go'
66--- snappy/errors.go 2015-05-26 09:21:05 +0000
67+++ snappy/errors.go 2015-06-04 15:01:05 +0000
68@@ -21,6 +21,8 @@
69 "errors"
70 "fmt"
71 "strings"
72+
73+ "launchpad.net/snappy/helpers"
74 )
75
76 var (
77@@ -143,6 +145,16 @@
78 ErrInvalidPart = errors.New("invalid package on system")
79 )
80
81+// ErrArchitectureNotSupported is returned when trying to install a snappy package that
82+// is not supported on the system
83+type ErrArchitectureNotSupported struct {
84+ architectures []string
85+}
86+
87+func (e *ErrArchitectureNotSupported) Error() string {
88+ return fmt.Sprintf("package's supported architectures (%s) is incompatible with this system (%s)", strings.Join(e.architectures, ", "), helpers.UbuntuArchitecture())
89+}
90+
91 // ErrInstallFailed is an error type for installation errors for snaps
92 type ErrInstallFailed struct {
93 snap string
94
95=== modified file 'snappy/snapp_test.go'
96--- snappy/snapp_test.go 2015-04-22 09:06:36 +0000
97+++ snappy/snapp_test.go 2015-06-04 15:01:05 +0000
98@@ -18,6 +18,7 @@
99 package snappy
100
101 import (
102+ "fmt"
103 "io"
104 "io/ioutil"
105 "net/http"
106@@ -698,6 +699,22 @@
107 c.Check(p.notified[0], Matches, "Waiting for .* stop.")
108 }
109
110+func (s *SnapTestSuite) TestErrorOnUnsupportedArchitecture(c *C) {
111+ const packageHello = `name: hello-app
112+version: 1.10
113+vendor: Somebody
114+icon: meta/hello.svg
115+architectures:
116+ - yadayada
117+ - blahblah
118+`
119+
120+ snapPkg := makeTestSnapPackage(c, packageHello)
121+ _, err := installClick(snapPkg, 0, nil, testNamespace)
122+ errorMsg := fmt.Sprintf("package's supported architectures (yadayada, blahblah) is incompatible with this system (%s)", helpers.UbuntuArchitecture())
123+ c.Assert(err.Error(), Equals, errorMsg)
124+}
125+
126 func (s *SnapTestSuite) TestRemoteSnapErrors(c *C) {
127 snap := RemoteSnapPart{}
128

Subscribers

People subscribed via source and target branches