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
=== modified file 'snappy/errors.go'
--- snappy/errors.go 2015-04-08 21:19:44 +0000
+++ snappy/errors.go 2015-04-09 13:16:52 +0000
@@ -179,3 +179,10 @@
179func (e ErrMissingFrameworks) Error() string {179func (e ErrMissingFrameworks) Error() string {
180 return fmt.Sprintf("missing frameworks: %s", strings.Join(e, ", "))180 return fmt.Sprintf("missing frameworks: %s", strings.Join(e, ", "))
181}181}
182
183// ErrFrameworkInUse reports that a framework is still needed by apps currently installed
184type ErrFrameworkInUse []string
185
186func (e ErrFrameworkInUse) Error() string {
187 return fmt.Sprintf("framework still in use by: %s", strings.Join(e, ", "))
188}
182189
=== modified file 'snappy/snapp.go'
--- snappy/snapp.go 2015-04-08 21:19:44 +0000
+++ snappy/snapp.go 2015-04-09 13:16:52 +0000
@@ -399,6 +399,14 @@
399 return ErrPackageNotRemovable399 return ErrPackageNotRemovable
400 }400 }
401401
402 deps, err := s.Dependents()
403 if err != nil {
404 return err
405 }
406 if len(deps) != 0 {
407 return ErrFrameworkInUse(deps)
408 }
409
402 return removeClick(s.basedir, pb)410 return removeClick(s.basedir, pb)
403}411}
404412
@@ -417,6 +425,38 @@
417 return s.m.Frameworks, nil425 return s.m.Frameworks, nil
418}426}
419427
428// Dependents gives the list of apps installed that depend on this one
429//
430// /!\ not part of the Part interface.
431func (s *SnapPart) Dependents() ([]string, error) {
432 if s.Type() != SnapTypeFramework {
433 // only frameworks are depended on
434 return nil, nil
435 }
436
437 var needed []string
438
439 installed, err := NewMetaRepository().Installed()
440 if err != nil {
441 return nil, err
442 }
443
444 name := s.Name()
445 for _, part := range installed {
446 fmks, err := part.Frameworks()
447 if err != nil {
448 return nil, err
449 }
450 for _, fmk := range fmks {
451 if fmk == name {
452 needed = append(needed, part.Name())
453 }
454 }
455 }
456
457 return needed, nil
458}
459
420// SnapLocalRepository is the type for a local snap repository460// SnapLocalRepository is the type for a local snap repository
421type SnapLocalRepository struct {461type SnapLocalRepository struct {
422 path string462 path string
423463
=== modified file 'snappy/snapp_test.go'
--- snappy/snapp_test.go 2015-04-09 08:57:40 +0000
+++ snappy/snapp_test.go 2015-04-09 13:16:52 +0000
@@ -781,3 +781,40 @@
781 err = yaml.checkForFrameworks()781 err = yaml.checkForFrameworks()
782 c.Assert(err, ErrorMatches, `missing frameworks: missing, also-missing`)782 c.Assert(err, ErrorMatches, `missing frameworks: missing, also-missing`)
783}783}
784
785func (s *SnapTestSuite) TestDetectsFrameworksInUse(c *C) {
786 _, err := makeInstalledMockSnap(s.tempdir, `name: foo
787version: 1.0
788frameworks:
789 - fmk
790`)
791 c.Assert(err, IsNil)
792
793 yaml, err := parsePackageYamlData([]byte(`name: fmk
794version: 1.0
795type: framework`))
796 c.Assert(err, IsNil)
797 part := &SnapPart{m: yaml}
798 deps, err := part.Dependents()
799 c.Assert(err, IsNil)
800 c.Check(deps, DeepEquals, []string{"foo"})
801}
802
803func (s *SnapTestSuite) TestRemoveChecksFrameworks(c *C) {
804 yamlFile, err := makeInstalledMockSnap(s.tempdir, `name: fmk
805version: 1.0
806type: framework`)
807 c.Assert(err, IsNil)
808 yaml, err := parsePackageYamlFile(yamlFile)
809
810 _, err = makeInstalledMockSnap(s.tempdir, `name: foo
811version: 1.0
812frameworks:
813 - fmk
814`)
815 c.Assert(err, IsNil)
816
817 part := &SnapPart{m: yaml}
818 err = part.Uninstall(new(MockProgressMeter))
819 c.Check(err, ErrorMatches, `framework still in use by: foo`)
820}

Subscribers

People subscribed via source and target branches