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

Proposed by John Lenton on 2015-05-29
Status: Merged
Approved by: Sergio Schvezov on 2015-06-09
Approved revision: 484
Merged at revision: 495
Proposed branch: lp:~chipaca/snappy/removeClick
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~chipaca/snappy/filepath
Diff against target: 174 lines (+58/-37)
4 files modified
snappy/click.go (+0/-29)
snappy/click_test.go (+22/-5)
snappy/purge_test.go (+7/-2)
snappy/snapp.go (+29/-1)
To merge this branch: bzr merge lp:~chipaca/snappy/removeClick
Reviewer Review Type Date Requested Status
Sergio Schvezov 2015-05-29 Approve on 2015-06-09
Review via email: mp+260560@code.launchpad.net

Commit Message

Move removeClick to be a method of SnapPart. Get rid of some spurious packageYaml (and click manifest!?!) parsing this way.

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

this looks great, I'm just nitpicking on the code comments (one is a carry over).

review: Needs Information
John Lenton (chipaca) :
lp:~chipaca/snappy/removeClick updated on 2015-06-08
482. By John Lenton on 2015-05-29

Merged filepath into removeClick.

483. By John Lenton on 2015-06-08

Merged filepath into removeClick.

484. By John Lenton on 2015-06-08

improved "maybe" comment

John Lenton (chipaca) wrote :

Done.

John Lenton (chipaca) wrote :

Note the “maybe” comment goes away in unsetActiveClick anyway :)
(addressing this here conflicted...)

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-06-04 22:21:51 +0000
3+++ snappy/click.go 2015-06-08 17:44:19 +0000
4@@ -262,35 +262,6 @@
5 return manifest, err
6 }
7
8-func removeClick(clickDir string, inter interacter) (err error) {
9- m, err := parsePackageYamlFile(filepath.Join(clickDir, "meta", "package.yaml"))
10- if err != nil {
11- return err
12- }
13-
14- if err := removeClickHooks(m, originFromBasedir(clickDir), false); err != nil {
15- return err
16- }
17-
18- // maybe remove current symlink
19- currentSymlink := filepath.Join(filepath.Dir(clickDir), "current")
20- p, _ := filepath.EvalSymlinks(currentSymlink)
21- if clickDir == p {
22- if err := unsetActiveClick(p, false, inter); err != nil {
23- return err
24- }
25- }
26-
27- err = os.RemoveAll(clickDir)
28- if err != nil {
29- return err
30- }
31-
32- os.Remove(filepath.Dir(clickDir))
33-
34- return nil
35-}
36-
37 // generate the name
38 func generateBinaryName(m *packageYaml, binary Binary) string {
39 var binName string
40
41=== modified file 'snappy/click_test.go'
42--- snappy/click_test.go 2015-06-03 14:03:45 +0000
43+++ snappy/click_test.go 2015-06-08 17:44:19 +0000
44@@ -357,7 +357,10 @@
45 _, err = os.Stat(instDir)
46 c.Assert(err, IsNil)
47
48- err = removeClick(instDir, nil)
49+ yamlPath := filepath.Join(instDir, "meta", "package.yaml")
50+ part, err := NewInstalledSnapPart(yamlPath, testOrigin)
51+ c.Assert(err, IsNil)
52+ err = part.remove(nil)
53 c.Assert(err, IsNil)
54
55 _, err = os.Stat(instDir)
56@@ -429,7 +432,11 @@
57
58 s.buildFramework(c)
59 appdir := filepath.Join(s.tempdir, "apps", "hello", "1.0.1")
60- c.Assert(removeClick(appdir, nil), IsNil)
61+ yamlPath := filepath.Join(appdir, "meta", "package.yaml")
62+ part, err := NewInstalledSnapPart(yamlPath, testOrigin)
63+ c.Assert(err, IsNil)
64+ err = part.remove(nil)
65+ c.Assert(err, IsNil)
66 }
67
68 func (s *SnapTestSuite) TestSnapRemovePackagePolicyWeirdClickManifest(c *C) {
69@@ -444,7 +451,11 @@
70 manifestFile := filepath.Join(appdir, ".click", "info", "hello.manifest")
71 c.Assert(ioutil.WriteFile(manifestFile, []byte(`{"name": "xyzzy","type":"framework"}`), 0644), IsNil)
72
73- c.Assert(removeClick(appdir, nil), IsNil)
74+ yamlPath := filepath.Join(appdir, "meta", "package.yaml")
75+ part, err := NewInstalledSnapPart(yamlPath, testOrigin)
76+ c.Assert(err, IsNil)
77+ err = part.remove(nil)
78+ c.Assert(err, IsNil)
79 }
80
81 func (s *SnapTestSuite) TestLocalOemSnapInstall(c *C) {
82@@ -810,7 +821,10 @@
83
84 // and that it gets removed on remove
85 snapDir := filepath.Join(snapAppsDir, "foo.mvo", "1.0")
86- err = removeClick(snapDir, nil)
87+ yamlPath := filepath.Join(snapDir, "meta", "package.yaml")
88+ part, err := NewInstalledSnapPart(yamlPath, testOrigin)
89+ c.Assert(err, IsNil)
90+ err = part.remove(nil)
91 c.Assert(err, IsNil)
92 c.Assert(helpers.FileExists(binaryWrapper), Equals, false)
93 c.Assert(helpers.FileExists(snapDir), Equals, false)
94@@ -866,7 +880,10 @@
95
96 // and that it gets removed on remove
97 snapDir := filepath.Join(snapAppsDir, "foo.mvo", "1.0")
98- err = removeClick(snapDir, new(progress.NullProgress))
99+ yamlPath := filepath.Join(snapDir, "meta", "package.yaml")
100+ part, err := NewInstalledSnapPart(yamlPath, testOrigin)
101+ c.Assert(err, IsNil)
102+ err = part.remove(&progress.NullProgress{})
103 c.Assert(err, IsNil)
104 c.Assert(helpers.FileExists(servicesFile), Equals, false)
105 c.Assert(helpers.FileExists(snapDir), Equals, false)
106
107=== modified file 'snappy/purge_test.go'
108--- snappy/purge_test.go 2015-06-02 20:46:07 +0000
109+++ snappy/purge_test.go 2015-06-08 17:44:19 +0000
110@@ -183,10 +183,15 @@
111 func (s *purgeSuite) TestPurgeRemovedWorks(c *C) {
112 inter := &MockProgressMeter{}
113 pkgdir, ddir := s.mkpkg(c)
114- c.Assert(removeClick(pkgdir, inter), IsNil)
115+
116+ yamlPath := filepath.Join(pkgdir, "meta", "package.yaml")
117+ part, err := NewInstalledSnapPart(yamlPath, testOrigin)
118+ c.Assert(err, IsNil)
119+ err = part.remove(inter)
120+ c.Assert(err, IsNil)
121 c.Check(helpers.FileExists(ddir), Equals, true)
122
123- err := Purge("hello-app", 0, inter)
124+ err = Purge("hello-app", 0, inter)
125 c.Check(err, IsNil)
126 c.Check(helpers.FileExists(ddir), Equals, false)
127 }
128
129=== modified file 'snappy/snapp.go'
130--- snappy/snapp.go 2015-06-04 12:55:54 +0000
131+++ snappy/snapp.go 2015-06-08 17:44:19 +0000
132@@ -855,13 +855,41 @@
133 return ErrFrameworkInUse(deps)
134 }
135
136- if err := removeClick(s.basedir, pb); err != nil {
137+ if err := s.remove(pb); err != nil {
138 return err
139 }
140
141 return RemoveAllHWAccess(QualifiedName(s))
142 }
143
144+func (s *SnapPart) remove(inter interacter) (err error) {
145+ // TODO[JRL]: check the logic here. I'm not sure “remove
146+ // everything if active, and the click hooks if not” makes
147+ // sense. E.g. are we removing fmk bins on fmk upgrade? Etc.
148+ if err := removeClickHooks(s.m, s.origin, false); err != nil {
149+ return err
150+ }
151+
152+ // remove "current" symlink if it points to this SnapPart
153+ // (i.e. if this was the active version).
154+ currentSymlink := filepath.Join(filepath.Dir(s.basedir), "current")
155+ p, _ := filepath.EvalSymlinks(currentSymlink)
156+ if s.basedir == p {
157+ if err := unsetActiveClick(p, false, inter); err != nil {
158+ return err
159+ }
160+ }
161+
162+ err = os.RemoveAll(s.basedir)
163+ if err != nil {
164+ return err
165+ }
166+
167+ os.Remove(filepath.Dir(s.basedir))
168+
169+ return nil
170+}
171+
172 // Config is used to to configure the snap
173 func (s *SnapPart) Config(configuration []byte) (new string, err error) {
174 return snapConfig(s.basedir, s.origin, string(configuration))

Subscribers

People subscribed via source and target branches