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
=== added directory 'pkg/removed'
=== added file 'pkg/removed/removed.go'
--- pkg/removed/removed.go 1970-01-01 00:00:00 +0000
+++ pkg/removed/removed.go 2015-10-07 16:07:50 +0000
@@ -0,0 +1,158 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2014-2015 Canonical Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20// Package removed implements Removed packages, that are packages that
21// have been installed, removed, but not purged: there is no
22// application, but there might be data.
23package removed
24
25import (
26 "errors"
27 "io/ioutil"
28 "time"
29
30 "gopkg.in/yaml.v2"
31
32 "launchpad.net/snappy/pkg"
33 "launchpad.net/snappy/pkg/remote"
34 "launchpad.net/snappy/progress"
35 "launchpad.net/snappy/snappy"
36)
37
38// ErrRemoved is returned when you ask to operate on a removed package.
39var ErrRemoved = errors.New("package is removed")
40
41// Removed represents a removed package.
42type Removed struct {
43 name string
44 origin string
45 version string
46 pkgType pkg.Type
47 remote *remote.Snap
48}
49
50// New removed package.
51func New(name, origin, version string, pkgType pkg.Type) snappy.Part {
52 part := &Removed{
53 name: name,
54 origin: origin,
55 version: version,
56 pkgType: pkgType,
57 }
58
59 // try to load the remote manifest, that would've been kept
60 // around when installing from the store.
61 content, _ := ioutil.ReadFile(snappy.RemoteManifestPath(part))
62 yaml.Unmarshal(content, &(part.remote))
63
64 return part
65}
66
67// Name from the snappy.Part interface
68func (r *Removed) Name() string { return r.name }
69
70// Version from the snappy.Part interface
71func (r *Removed) Version() string { return r.version }
72
73// Description from the snappy.Part interface
74func (r *Removed) Description() string {
75 if r.remote != nil {
76 return r.remote.Description
77 }
78
79 return ""
80}
81
82// Origin from the snappy.Part interface
83func (r *Removed) Origin() string {
84 if r.remote != nil {
85 return r.remote.Origin
86 }
87 if r.origin == "" {
88 return snappy.SideloadedOrigin
89 }
90 return r.origin
91}
92
93// Vendor from the snappy.Part interface
94func (r *Removed) Vendor() string {
95 if r.remote != nil {
96 return r.remote.Publisher
97 }
98
99 return ""
100}
101
102// Hash from the snappy.Part interface
103func (r *Removed) Hash() string { return "" }
104
105// IsActive from the snappy.Part interface
106func (r *Removed) IsActive() bool { return false }
107
108// IsInstalled from the snappy.Part interface
109func (r *Removed) IsInstalled() bool { return false }
110
111// NeedsReboot from the snappy.Part interface
112func (r *Removed) NeedsReboot() bool { return false }
113
114// Date from the snappy.Part interface
115func (r *Removed) Date() time.Time { return time.Time{} } // XXX: keep track of when the package was removed
116// Channel from the snappy.Part interface
117func (r *Removed) Channel() string { return "" }
118
119// Icon from the snappy.Part interface
120func (r *Removed) Icon() string {
121 if r.remote != nil {
122 return r.remote.IconURL
123 }
124
125 return ""
126}
127
128// Type from the snappy.Part interface
129func (r *Removed) Type() pkg.Type { return r.pkgType }
130
131// InstalledSize from the snappy.Part interface
132func (r *Removed) InstalledSize() int64 { return -1 }
133
134// DownloadSize from the snappy.Part interface
135func (r *Removed) DownloadSize() int64 {
136 if r.remote != nil {
137 return r.remote.DownloadSize
138 }
139
140 return -1
141}
142
143// Install from the snappy.Part interface
144func (r *Removed) Install(pb progress.Meter, flags snappy.InstallFlags) (name string, err error) {
145 return "", ErrRemoved
146}
147
148// Uninstall from the snappy.Part interface
149func (r *Removed) Uninstall(pb progress.Meter) error { return ErrRemoved }
150
151// Config from the snappy.Part interface
152func (r *Removed) Config(configuration []byte) (newConfig string, err error) { return "", ErrRemoved }
153
154// SetActive from the snappy.Part interface
155func (r *Removed) SetActive(bool, progress.Meter) error { return ErrRemoved }
156
157// Frameworks from the snappy.Part interface
158func (r *Removed) Frameworks() ([]string, error) { return nil, ErrRemoved }
0159
=== added file 'pkg/removed/removed_test.go'
--- pkg/removed/removed_test.go 1970-01-01 00:00:00 +0000
+++ pkg/removed/removed_test.go 2015-10-07 16:07:50 +0000
@@ -0,0 +1,137 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2014-2015 Canonical Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20package removed
21
22import (
23 "io/ioutil"
24 "os"
25 "path/filepath"
26 "testing"
27
28 "gopkg.in/check.v1"
29
30 "launchpad.net/snappy/dirs"
31 "launchpad.net/snappy/pkg"
32 "launchpad.net/snappy/progress"
33 "launchpad.net/snappy/snappy"
34)
35
36type removedSuite struct{}
37
38func Test(t *testing.T) { check.TestingT(t) }
39
40var _ = check.Suite(&removedSuite{})
41
42func (s *removedSuite) SetUpTest(c *check.C) {
43 dirs.SetRootDir(c.MkDir())
44 c.Check(os.MkdirAll(filepath.Join(dirs.SnapDataDir, "foo.bar", "1"), 0755), check.IsNil)
45}
46
47func (s *removedSuite) MkStoreYaml(c *check.C, pkgType pkg.Type) {
48 // creating the part to get its manifest path is cheating, a little
49 part := &Removed{
50 name: "foo",
51 origin: "bar",
52 version: "1",
53 pkgType: pkgType,
54 }
55
56 content := `
57name: foo
58origin: bar
59version: 1
60type: app
61description: |-
62 bla bla bla
63publisher: example.com
64iconurl: http://i.stack.imgur.com/i8q1U.jpg
65downloadsize: 5554242
66`
67 p := snappy.RemoteManifestPath(part)
68 c.Assert(os.MkdirAll(filepath.Dir(p), 0755), check.IsNil)
69 c.Assert(ioutil.WriteFile(p, []byte(content), 0644), check.IsNil)
70
71}
72
73func (s *removedSuite) TestNoStore(c *check.C) {
74 part := New("foo", "bar", "1", pkg.TypeApp)
75
76 c.Check(part.Name(), check.Equals, "foo")
77 c.Check(part.Origin(), check.Equals, "bar")
78 c.Check(part.Version(), check.Equals, "1")
79 c.Check(part.Description(), check.Equals, "")
80 c.Check(part.Vendor(), check.Equals, "")
81 c.Check(part.Hash(), check.Equals, "")
82 c.Check(part.Icon(), check.Equals, "")
83 c.Check(part.DownloadSize(), check.Equals, int64(-1))
84
85 c.Check(part.InstalledSize(), check.Equals, int64(-1))
86 c.Check(part.IsActive(), check.Equals, false)
87 c.Check(part.IsInstalled(), check.Equals, false)
88 c.Check(part.NeedsReboot(), check.Equals, false)
89
90 prog := &progress.NullProgress{}
91 c.Check(part.Uninstall(prog), check.Equals, ErrRemoved)
92 c.Check(part.SetActive(true, prog), check.Equals, ErrRemoved)
93 _, err := part.Install(prog, 0)
94 c.Check(err, check.Equals, ErrRemoved)
95 _, err = part.Config(nil)
96 c.Check(err, check.Equals, ErrRemoved)
97 _, err = part.Frameworks()
98 c.Check(err, check.Equals, ErrRemoved)
99}
100
101func (s *removedSuite) TestNoOrigin(c *check.C) {
102 part := New("foo", "", "1", pkg.TypeFramework)
103 c.Check(part.Origin(), check.Equals, snappy.SideloadedOrigin)
104
105 s.MkStoreYaml(c, pkg.TypeFramework)
106 part = New("foo", "", "1", pkg.TypeFramework)
107 c.Check(part.Origin(), check.Equals, "bar")
108}
109
110func (s *removedSuite) TestWithStore(c *check.C) {
111 s.MkStoreYaml(c, pkg.TypeApp)
112 part := New("foo", "bar", "1", pkg.TypeApp)
113
114 c.Check(part.Name(), check.Equals, "foo")
115 c.Check(part.Origin(), check.Equals, "bar")
116 c.Check(part.Version(), check.Equals, "1")
117 c.Check(part.Description(), check.Equals, "bla bla bla")
118 c.Check(part.Vendor(), check.Equals, "example.com")
119 c.Check(part.Hash(), check.Equals, "")
120 c.Check(part.Icon(), check.Equals, "http://i.stack.imgur.com/i8q1U.jpg")
121 c.Check(part.DownloadSize(), check.Equals, int64(5554242))
122
123 c.Check(part.InstalledSize(), check.Equals, int64(-1))
124 c.Check(part.IsActive(), check.Equals, false)
125 c.Check(part.IsInstalled(), check.Equals, false)
126 c.Check(part.NeedsReboot(), check.Equals, false)
127
128 prog := &progress.NullProgress{}
129 c.Check(part.Uninstall(prog), check.Equals, ErrRemoved)
130 c.Check(part.SetActive(true, prog), check.Equals, ErrRemoved)
131 _, err := part.Install(prog, 0)
132 c.Check(err, check.Equals, ErrRemoved)
133 _, err = part.Config(nil)
134 c.Check(err, check.Equals, ErrRemoved)
135 _, err = part.Frameworks()
136 c.Check(err, check.Equals, ErrRemoved)
137}
0138
=== modified file 'snappy/parts.go'
--- snappy/parts.go 2015-10-07 16:07:49 +0000
+++ snappy/parts.go 2015-10-07 16:07:50 +0000
@@ -361,7 +361,7 @@
361 return filepath.Join(dirs.SnapIconsDir, fmt.Sprintf("%s_%s.png", QualifiedName(s), s.Version()))361 return filepath.Join(dirs.SnapIconsDir, fmt.Sprintf("%s_%s.png", QualifiedName(s), s.Version()))
362}362}
363363
364// ManifestPath returns the would be path for the store manifest meta data364// RemoteManifestPath returns the would be path for the store manifest meta data
365func ManifestPath(s Part) string {365func RemoteManifestPath(s Part) string {
366 return filepath.Join(dirs.SnapMetaDir, fmt.Sprintf("%s_%s.manifest", QualifiedName(s), s.Version()))366 return filepath.Join(dirs.SnapMetaDir, fmt.Sprintf("%s_%s.manifest", QualifiedName(s), s.Version()))
367}367}
368368
=== modified file 'snappy/snapp.go'
--- snappy/snapp.go 2015-10-07 16:07:49 +0000
+++ snappy/snapp.go 2015-10-07 16:07:50 +0000
@@ -634,7 +634,7 @@
634 }634 }
635 part.hash = h.ArchiveSha512635 part.hash = h.ArchiveSha512
636636
637 remoteManifestPath := ManifestPath(part)637 remoteManifestPath := RemoteManifestPath(part)
638 if helpers.FileExists(remoteManifestPath) {638 if helpers.FileExists(remoteManifestPath) {
639 content, err := ioutil.ReadFile(remoteManifestPath)639 content, err := ioutil.ReadFile(remoteManifestPath)
640 if err != nil {640 if err != nil {
@@ -1615,7 +1615,7 @@
1615 }1615 }
16161616
1617 // don't worry about previous contents1617 // don't worry about previous contents
1618 return ioutil.WriteFile(ManifestPath(s), content, 0644)1618 return ioutil.WriteFile(RemoteManifestPath(s), content, 0644)
1619}1619}
16201620
1621// Install installs the snap1621// Install installs the snap

Subscribers

People subscribed via source and target branches