Merge lp:~chipaca/snappy/remove-framework-aborts-on-dependent-snap into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 330
Merged at revision: 327
Proposed branch: lp:~chipaca/snappy/remove-framework-aborts-on-dependent-snap
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 117 lines (+84/-0)
3 files modified
snappy/errors.go (+7/-0)
snappy/snapp.go (+40/-0)
snappy/snapp_test.go (+37/-0)
To merge this branch: bzr merge lp:~chipaca/snappy/remove-framework-aborts-on-dependent-snap
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+255626@code.launchpad.net

Commit message

Check for dependents on framework remove.

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

Thanks, this looks nice and straightforward. One minor naming suggestion inline, feel free to top-approve once resolved (either by renaming or keeping).

review: Approve
330. By John Lenton

renamed error as per mvo suggestion

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy/errors.go'
2--- snappy/errors.go 2015-04-08 21:19:44 +0000
3+++ snappy/errors.go 2015-04-09 13:16:52 +0000
4@@ -179,3 +179,10 @@
5 func (e ErrMissingFrameworks) Error() string {
6 return fmt.Sprintf("missing frameworks: %s", strings.Join(e, ", "))
7 }
8+
9+// ErrFrameworkInUse reports that a framework is still needed by apps currently installed
10+type ErrFrameworkInUse []string
11+
12+func (e ErrFrameworkInUse) Error() string {
13+ return fmt.Sprintf("framework still in use by: %s", strings.Join(e, ", "))
14+}
15
16=== modified file 'snappy/snapp.go'
17--- snappy/snapp.go 2015-04-08 21:19:44 +0000
18+++ snappy/snapp.go 2015-04-09 13:16:52 +0000
19@@ -399,6 +399,14 @@
20 return ErrPackageNotRemovable
21 }
22
23+ deps, err := s.Dependents()
24+ if err != nil {
25+ return err
26+ }
27+ if len(deps) != 0 {
28+ return ErrFrameworkInUse(deps)
29+ }
30+
31 return removeClick(s.basedir, pb)
32 }
33
34@@ -417,6 +425,38 @@
35 return s.m.Frameworks, nil
36 }
37
38+// Dependents gives the list of apps installed that depend on this one
39+//
40+// /!\ not part of the Part interface.
41+func (s *SnapPart) Dependents() ([]string, error) {
42+ if s.Type() != SnapTypeFramework {
43+ // only frameworks are depended on
44+ return nil, nil
45+ }
46+
47+ var needed []string
48+
49+ installed, err := NewMetaRepository().Installed()
50+ if err != nil {
51+ return nil, err
52+ }
53+
54+ name := s.Name()
55+ for _, part := range installed {
56+ fmks, err := part.Frameworks()
57+ if err != nil {
58+ return nil, err
59+ }
60+ for _, fmk := range fmks {
61+ if fmk == name {
62+ needed = append(needed, part.Name())
63+ }
64+ }
65+ }
66+
67+ return needed, nil
68+}
69+
70 // SnapLocalRepository is the type for a local snap repository
71 type SnapLocalRepository struct {
72 path string
73
74=== modified file 'snappy/snapp_test.go'
75--- snappy/snapp_test.go 2015-04-09 08:57:40 +0000
76+++ snappy/snapp_test.go 2015-04-09 13:16:52 +0000
77@@ -781,3 +781,40 @@
78 err = yaml.checkForFrameworks()
79 c.Assert(err, ErrorMatches, `missing frameworks: missing, also-missing`)
80 }
81+
82+func (s *SnapTestSuite) TestDetectsFrameworksInUse(c *C) {
83+ _, err := makeInstalledMockSnap(s.tempdir, `name: foo
84+version: 1.0
85+frameworks:
86+ - fmk
87+`)
88+ c.Assert(err, IsNil)
89+
90+ yaml, err := parsePackageYamlData([]byte(`name: fmk
91+version: 1.0
92+type: framework`))
93+ c.Assert(err, IsNil)
94+ part := &SnapPart{m: yaml}
95+ deps, err := part.Dependents()
96+ c.Assert(err, IsNil)
97+ c.Check(deps, DeepEquals, []string{"foo"})
98+}
99+
100+func (s *SnapTestSuite) TestRemoveChecksFrameworks(c *C) {
101+ yamlFile, err := makeInstalledMockSnap(s.tempdir, `name: fmk
102+version: 1.0
103+type: framework`)
104+ c.Assert(err, IsNil)
105+ yaml, err := parsePackageYamlFile(yamlFile)
106+
107+ _, err = makeInstalledMockSnap(s.tempdir, `name: foo
108+version: 1.0
109+frameworks:
110+ - fmk
111+`)
112+ c.Assert(err, IsNil)
113+
114+ part := &SnapPart{m: yaml}
115+ err = part.Uninstall(new(MockProgressMeter))
116+ c.Check(err, ErrorMatches, `framework still in use by: foo`)
117+}

Subscribers

People subscribed via source and target branches