Merge lp:~chipaca/snappy/removed-pkg into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 744
Merged at revision: 744
Proposed branch: lp:~chipaca/snappy/removed-pkg
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~chipaca/snappy/remote-snap
Diff against target: 341 lines (+299/-4)
4 files modified
pkg/removed/removed.go (+158/-0)
pkg/removed/removed_test.go (+137/-0)
snappy/parts.go (+2/-2)
snappy/snapp.go (+2/-2)
To merge this branch: bzr merge lp:~chipaca/snappy/removed-pkg
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+273481@code.launchpad.net

Commit message

Introducing removed parts. Also, renamed ManifestPath -> RemoteManifestPath for clarity.

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

This looks great, thanks! One inline comment that to maybe improves readability. But that can be a separate branch of course.

review: Approve
lp:~chipaca/snappy/removed-pkg updated
743. By John Lenton

Merged remote-snap into removed-pkg.

744. By John Lenton

clarified ManifestPath (-> RemoteManifestPath, + a comment)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'pkg/removed'
2=== added file 'pkg/removed/removed.go'
3--- pkg/removed/removed.go 1970-01-01 00:00:00 +0000
4+++ pkg/removed/removed.go 2015-10-07 16:07:50 +0000
5@@ -0,0 +1,158 @@
6+// -*- Mode: Go; indent-tabs-mode: t -*-
7+
8+/*
9+ * Copyright (C) 2014-2015 Canonical Ltd
10+ *
11+ * This program is free software: you can redistribute it and/or modify
12+ * it under the terms of the GNU General Public License version 3 as
13+ * published by the Free Software Foundation.
14+ *
15+ * This program is distributed in the hope that it will be useful,
16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+ * GNU General Public License for more details.
19+ *
20+ * You should have received a copy of the GNU General Public License
21+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
22+ *
23+ */
24+
25+// Package removed implements Removed packages, that are packages that
26+// have been installed, removed, but not purged: there is no
27+// application, but there might be data.
28+package removed
29+
30+import (
31+ "errors"
32+ "io/ioutil"
33+ "time"
34+
35+ "gopkg.in/yaml.v2"
36+
37+ "launchpad.net/snappy/pkg"
38+ "launchpad.net/snappy/pkg/remote"
39+ "launchpad.net/snappy/progress"
40+ "launchpad.net/snappy/snappy"
41+)
42+
43+// ErrRemoved is returned when you ask to operate on a removed package.
44+var ErrRemoved = errors.New("package is removed")
45+
46+// Removed represents a removed package.
47+type Removed struct {
48+ name string
49+ origin string
50+ version string
51+ pkgType pkg.Type
52+ remote *remote.Snap
53+}
54+
55+// New removed package.
56+func New(name, origin, version string, pkgType pkg.Type) snappy.Part {
57+ part := &Removed{
58+ name: name,
59+ origin: origin,
60+ version: version,
61+ pkgType: pkgType,
62+ }
63+
64+ // try to load the remote manifest, that would've been kept
65+ // around when installing from the store.
66+ content, _ := ioutil.ReadFile(snappy.RemoteManifestPath(part))
67+ yaml.Unmarshal(content, &(part.remote))
68+
69+ return part
70+}
71+
72+// Name from the snappy.Part interface
73+func (r *Removed) Name() string { return r.name }
74+
75+// Version from the snappy.Part interface
76+func (r *Removed) Version() string { return r.version }
77+
78+// Description from the snappy.Part interface
79+func (r *Removed) Description() string {
80+ if r.remote != nil {
81+ return r.remote.Description
82+ }
83+
84+ return ""
85+}
86+
87+// Origin from the snappy.Part interface
88+func (r *Removed) Origin() string {
89+ if r.remote != nil {
90+ return r.remote.Origin
91+ }
92+ if r.origin == "" {
93+ return snappy.SideloadedOrigin
94+ }
95+ return r.origin
96+}
97+
98+// Vendor from the snappy.Part interface
99+func (r *Removed) Vendor() string {
100+ if r.remote != nil {
101+ return r.remote.Publisher
102+ }
103+
104+ return ""
105+}
106+
107+// Hash from the snappy.Part interface
108+func (r *Removed) Hash() string { return "" }
109+
110+// IsActive from the snappy.Part interface
111+func (r *Removed) IsActive() bool { return false }
112+
113+// IsInstalled from the snappy.Part interface
114+func (r *Removed) IsInstalled() bool { return false }
115+
116+// NeedsReboot from the snappy.Part interface
117+func (r *Removed) NeedsReboot() bool { return false }
118+
119+// Date from the snappy.Part interface
120+func (r *Removed) Date() time.Time { return time.Time{} } // XXX: keep track of when the package was removed
121+// Channel from the snappy.Part interface
122+func (r *Removed) Channel() string { return "" }
123+
124+// Icon from the snappy.Part interface
125+func (r *Removed) Icon() string {
126+ if r.remote != nil {
127+ return r.remote.IconURL
128+ }
129+
130+ return ""
131+}
132+
133+// Type from the snappy.Part interface
134+func (r *Removed) Type() pkg.Type { return r.pkgType }
135+
136+// InstalledSize from the snappy.Part interface
137+func (r *Removed) InstalledSize() int64 { return -1 }
138+
139+// DownloadSize from the snappy.Part interface
140+func (r *Removed) DownloadSize() int64 {
141+ if r.remote != nil {
142+ return r.remote.DownloadSize
143+ }
144+
145+ return -1
146+}
147+
148+// Install from the snappy.Part interface
149+func (r *Removed) Install(pb progress.Meter, flags snappy.InstallFlags) (name string, err error) {
150+ return "", ErrRemoved
151+}
152+
153+// Uninstall from the snappy.Part interface
154+func (r *Removed) Uninstall(pb progress.Meter) error { return ErrRemoved }
155+
156+// Config from the snappy.Part interface
157+func (r *Removed) Config(configuration []byte) (newConfig string, err error) { return "", ErrRemoved }
158+
159+// SetActive from the snappy.Part interface
160+func (r *Removed) SetActive(bool, progress.Meter) error { return ErrRemoved }
161+
162+// Frameworks from the snappy.Part interface
163+func (r *Removed) Frameworks() ([]string, error) { return nil, ErrRemoved }
164
165=== added file 'pkg/removed/removed_test.go'
166--- pkg/removed/removed_test.go 1970-01-01 00:00:00 +0000
167+++ pkg/removed/removed_test.go 2015-10-07 16:07:50 +0000
168@@ -0,0 +1,137 @@
169+// -*- Mode: Go; indent-tabs-mode: t -*-
170+
171+/*
172+ * Copyright (C) 2014-2015 Canonical Ltd
173+ *
174+ * This program is free software: you can redistribute it and/or modify
175+ * it under the terms of the GNU General Public License version 3 as
176+ * published by the Free Software Foundation.
177+ *
178+ * This program is distributed in the hope that it will be useful,
179+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
180+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
181+ * GNU General Public License for more details.
182+ *
183+ * You should have received a copy of the GNU General Public License
184+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
185+ *
186+ */
187+
188+package removed
189+
190+import (
191+ "io/ioutil"
192+ "os"
193+ "path/filepath"
194+ "testing"
195+
196+ "gopkg.in/check.v1"
197+
198+ "launchpad.net/snappy/dirs"
199+ "launchpad.net/snappy/pkg"
200+ "launchpad.net/snappy/progress"
201+ "launchpad.net/snappy/snappy"
202+)
203+
204+type removedSuite struct{}
205+
206+func Test(t *testing.T) { check.TestingT(t) }
207+
208+var _ = check.Suite(&removedSuite{})
209+
210+func (s *removedSuite) SetUpTest(c *check.C) {
211+ dirs.SetRootDir(c.MkDir())
212+ c.Check(os.MkdirAll(filepath.Join(dirs.SnapDataDir, "foo.bar", "1"), 0755), check.IsNil)
213+}
214+
215+func (s *removedSuite) MkStoreYaml(c *check.C, pkgType pkg.Type) {
216+ // creating the part to get its manifest path is cheating, a little
217+ part := &Removed{
218+ name: "foo",
219+ origin: "bar",
220+ version: "1",
221+ pkgType: pkgType,
222+ }
223+
224+ content := `
225+name: foo
226+origin: bar
227+version: 1
228+type: app
229+description: |-
230+ bla bla bla
231+publisher: example.com
232+iconurl: http://i.stack.imgur.com/i8q1U.jpg
233+downloadsize: 5554242
234+`
235+ p := snappy.RemoteManifestPath(part)
236+ c.Assert(os.MkdirAll(filepath.Dir(p), 0755), check.IsNil)
237+ c.Assert(ioutil.WriteFile(p, []byte(content), 0644), check.IsNil)
238+
239+}
240+
241+func (s *removedSuite) TestNoStore(c *check.C) {
242+ part := New("foo", "bar", "1", pkg.TypeApp)
243+
244+ c.Check(part.Name(), check.Equals, "foo")
245+ c.Check(part.Origin(), check.Equals, "bar")
246+ c.Check(part.Version(), check.Equals, "1")
247+ c.Check(part.Description(), check.Equals, "")
248+ c.Check(part.Vendor(), check.Equals, "")
249+ c.Check(part.Hash(), check.Equals, "")
250+ c.Check(part.Icon(), check.Equals, "")
251+ c.Check(part.DownloadSize(), check.Equals, int64(-1))
252+
253+ c.Check(part.InstalledSize(), check.Equals, int64(-1))
254+ c.Check(part.IsActive(), check.Equals, false)
255+ c.Check(part.IsInstalled(), check.Equals, false)
256+ c.Check(part.NeedsReboot(), check.Equals, false)
257+
258+ prog := &progress.NullProgress{}
259+ c.Check(part.Uninstall(prog), check.Equals, ErrRemoved)
260+ c.Check(part.SetActive(true, prog), check.Equals, ErrRemoved)
261+ _, err := part.Install(prog, 0)
262+ c.Check(err, check.Equals, ErrRemoved)
263+ _, err = part.Config(nil)
264+ c.Check(err, check.Equals, ErrRemoved)
265+ _, err = part.Frameworks()
266+ c.Check(err, check.Equals, ErrRemoved)
267+}
268+
269+func (s *removedSuite) TestNoOrigin(c *check.C) {
270+ part := New("foo", "", "1", pkg.TypeFramework)
271+ c.Check(part.Origin(), check.Equals, snappy.SideloadedOrigin)
272+
273+ s.MkStoreYaml(c, pkg.TypeFramework)
274+ part = New("foo", "", "1", pkg.TypeFramework)
275+ c.Check(part.Origin(), check.Equals, "bar")
276+}
277+
278+func (s *removedSuite) TestWithStore(c *check.C) {
279+ s.MkStoreYaml(c, pkg.TypeApp)
280+ part := New("foo", "bar", "1", pkg.TypeApp)
281+
282+ c.Check(part.Name(), check.Equals, "foo")
283+ c.Check(part.Origin(), check.Equals, "bar")
284+ c.Check(part.Version(), check.Equals, "1")
285+ c.Check(part.Description(), check.Equals, "bla bla bla")
286+ c.Check(part.Vendor(), check.Equals, "example.com")
287+ c.Check(part.Hash(), check.Equals, "")
288+ c.Check(part.Icon(), check.Equals, "http://i.stack.imgur.com/i8q1U.jpg")
289+ c.Check(part.DownloadSize(), check.Equals, int64(5554242))
290+
291+ c.Check(part.InstalledSize(), check.Equals, int64(-1))
292+ c.Check(part.IsActive(), check.Equals, false)
293+ c.Check(part.IsInstalled(), check.Equals, false)
294+ c.Check(part.NeedsReboot(), check.Equals, false)
295+
296+ prog := &progress.NullProgress{}
297+ c.Check(part.Uninstall(prog), check.Equals, ErrRemoved)
298+ c.Check(part.SetActive(true, prog), check.Equals, ErrRemoved)
299+ _, err := part.Install(prog, 0)
300+ c.Check(err, check.Equals, ErrRemoved)
301+ _, err = part.Config(nil)
302+ c.Check(err, check.Equals, ErrRemoved)
303+ _, err = part.Frameworks()
304+ c.Check(err, check.Equals, ErrRemoved)
305+}
306
307=== modified file 'snappy/parts.go'
308--- snappy/parts.go 2015-10-07 16:07:49 +0000
309+++ snappy/parts.go 2015-10-07 16:07:50 +0000
310@@ -361,7 +361,7 @@
311 return filepath.Join(dirs.SnapIconsDir, fmt.Sprintf("%s_%s.png", QualifiedName(s), s.Version()))
312 }
313
314-// ManifestPath returns the would be path for the store manifest meta data
315-func ManifestPath(s Part) string {
316+// RemoteManifestPath returns the would be path for the store manifest meta data
317+func RemoteManifestPath(s Part) string {
318 return filepath.Join(dirs.SnapMetaDir, fmt.Sprintf("%s_%s.manifest", QualifiedName(s), s.Version()))
319 }
320
321=== modified file 'snappy/snapp.go'
322--- snappy/snapp.go 2015-10-07 16:07:49 +0000
323+++ snappy/snapp.go 2015-10-07 16:07:50 +0000
324@@ -634,7 +634,7 @@
325 }
326 part.hash = h.ArchiveSha512
327
328- remoteManifestPath := ManifestPath(part)
329+ remoteManifestPath := RemoteManifestPath(part)
330 if helpers.FileExists(remoteManifestPath) {
331 content, err := ioutil.ReadFile(remoteManifestPath)
332 if err != nil {
333@@ -1615,7 +1615,7 @@
334 }
335
336 // don't worry about previous contents
337- return ioutil.WriteFile(ManifestPath(s), content, 0644)
338+ return ioutil.WriteFile(RemoteManifestPath(s), content, 0644)
339 }
340
341 // Install installs the snap

Subscribers

People subscribed via source and target branches