Merge lp:~sergiusens/snappy/YouShallNotPass into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Sergio Schvezov on 2015-06-04
Status: Merged
Approved by: John Lenton on 2015-06-04
Approved revision: 486
Merged at revision: 484
Proposed branch: lp:~sergiusens/snappy/YouShallNotPass
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 130 lines (+63/-0)
5 files modified
helpers/helpers.go (+14/-0)
helpers/helpers_test.go (+12/-0)
snappy/errors.go (+12/-0)
snappy/snapp.go (+5/-0)
snappy/snapp_test.go (+20/-0)
To merge this branch: bzr merge lp:~sergiusens/snappy/YouShallNotPass
Reviewer Review Type Date Requested Status
John Lenton 2015-06-04 Approve on 2015-06-04
Review via email: mp+261079@code.launchpad.net

Commit Message

Don't allow installation of packages with unsupported architectures

Description of the Change

I hope but don't think this will be able to be directly backported :-)

To post a comment you must log in.
John Lenton (chipaca) wrote :

Nice! One minuscule nit.

review: Approve
485. By Sergio Schvezov on 2015-06-04

comma space, always comma space

486. By Sergio Schvezov on 2015-06-04

Adding a test to test the error

Michael Vogt (mvo) :
Sergio Schvezov (sergiusens) wrote :

On Thu, Jun 04, 2015 at 09:26:57PM -0000, Michael Vogt wrote:
>
>
> Diff comments:
>
> > === modified file 'helpers/helpers.go'
> > --- helpers/helpers.go 2015-06-03 14:01:51 +0000
> > +++ helpers/helpers.go 2015-06-04 13:35:20 +0000
> > @@ -197,6 +197,20 @@
> > }
> > }
> >
> > +// IsSupportedArchitecture returns true if the system architecture is in the
> > +// list of architectures.
> > +func IsSupportedArchitecture(architectures []string) bool {
>
> I am a bit late to the party I guess so I shouldn't complain ;) I'm a bit uncertainy if helpers/ is the best place for this. Helpers a bit of a catch-all-bag but so far mostly for stuff that is pretty generic and could be re-used in very different projects than snappy. Not sure how well this fits. But then UbuntuArchitecture() is also in helpers so I guess its fine and I stop to jabber :)

The only reason I put this code in helpers is because UbuntuArchitecture
was already here; it also made backporting easier as there ir a major
refactor in clickInstall and SnapParts going on.

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 14:01:51 +0000
3+++ helpers/helpers.go 2015-06-04 13:35:20 +0000
4@@ -197,6 +197,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 // Sha512sum returns the sha512 of the given file as a hexdigest
23 func Sha512sum(infile string) (hexdigest string, err error) {
24 r, err := os.Open(infile)
25
26=== modified file 'helpers/helpers_test.go'
27--- helpers/helpers_test.go 2015-06-02 20:46:07 +0000
28+++ helpers/helpers_test.go 2015-06-04 13:35:20 +0000
29@@ -97,6 +97,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/errors.go'
50--- snappy/errors.go 2015-05-28 11:58:30 +0000
51+++ snappy/errors.go 2015-06-04 13:35:20 +0000
52@@ -23,6 +23,8 @@
53 "errors"
54 "fmt"
55 "strings"
56+
57+ "launchpad.net/snappy/helpers"
58 )
59
60 var (
61@@ -140,6 +142,16 @@
62 ErrInvalidSeccompPolicy = errors.New("policy-version and policy-vendor must be specified together")
63 )
64
65+// ErrArchitectureNotSupported is returned when trying to install a snappy package that
66+// is not supported on the system
67+type ErrArchitectureNotSupported struct {
68+ architectures []string
69+}
70+
71+func (e *ErrArchitectureNotSupported) Error() string {
72+ return fmt.Sprintf("package's supported architectures (%s) is incompatible with this system (%s)", strings.Join(e.architectures, ", "), helpers.UbuntuArchitecture())
73+}
74+
75 // ErrInstallFailed is an error type for installation errors for snaps
76 type ErrInstallFailed struct {
77 snap string
78
79=== modified file 'snappy/snapp.go'
80--- snappy/snapp.go 2015-05-29 13:22:14 +0000
81+++ snappy/snapp.go 2015-06-04 13:35:20 +0000
82@@ -941,6 +941,11 @@
83 return err
84 }
85
86+ // verify we have a valid architecture
87+ if !helpers.IsSupportedArchitecture(s.m.Architectures) {
88+ return &ErrArchitectureNotSupported{s.m.Architectures}
89+ }
90+
91 if err := s.m.checkForNameClashes(); err != nil {
92 return err
93 }
94
95=== modified file 'snappy/snapp_test.go'
96--- snappy/snapp_test.go 2015-06-02 20:46:07 +0000
97+++ snappy/snapp_test.go 2015-06-04 13:35:20 +0000
98@@ -20,6 +20,7 @@
99 package snappy
100
101 import (
102+ "fmt"
103 "io"
104 "io/ioutil"
105 "net/http"
106@@ -708,6 +709,25 @@
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+ part, err := NewSnapPartFromSnapFile(snapPkg, "original", true)
122+ c.Assert(err, IsNil)
123+
124+ _, err = part.Install(&MockProgressMeter{}, 0)
125+ errorMsg := fmt.Sprintf("package's supported architectures (yadayada, blahblah) is incompatible with this system (%s)", helpers.UbuntuArchitecture())
126+ c.Assert(err.Error(), Equals, errorMsg)
127+}
128+
129 func (s *SnapTestSuite) TestRemoteSnapErrors(c *C) {
130 snap := RemoteSnapPart{}
131

Subscribers

People subscribed via source and target branches