Merge lp:~sergiusens/snappy/policyRoot into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Sergio Schvezov
Status: Merged
Approved by: Michael Vogt
Approved revision: 506
Merged at revision: 508
Proposed branch: lp:~sergiusens/snappy/policyRoot
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 109 lines (+16/-14)
3 files modified
policy/policy.go (+7/-7)
policy/policy_test.go (+7/-5)
snappy/snapp.go (+2/-2)
To merge this branch: bzr merge lp:~sergiusens/snappy/policyRoot
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+261802@code.launchpad.net

Commit message

Consider the root directory when installing and removing policies

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

Good catch!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'policy/policy.go'
2--- policy/policy.go 2015-05-15 13:33:27 +0000
3+++ policy/policy.go 2015-06-12 03:58:44 +0000
4@@ -60,7 +60,7 @@
5 // Directories are created as needed. Errors out with any of the things that
6 // could go wrong with this, including a file found by glob not being a
7 // regular file.
8-func iterOp(op policyOp, glob string, targetDir string, prefix string) (err error) {
9+func iterOp(op policyOp, glob, targetDir, prefix string) (err error) {
10 if err = os.MkdirAll(targetDir, 0755); err != nil {
11 return fmt.Errorf("unable to make %v directory: %v", targetDir, err)
12 }
13@@ -104,11 +104,11 @@
14
15 // frameworkOp perform the given operation (either Install or Remove) on the
16 // given package that's installed in the given path.
17-func frameworkOp(op policyOp, pkgName string, instPath string) error {
18+func frameworkOp(op policyOp, pkgName, instPath, rootDir string) error {
19 pol := filepath.Join(instPath, "meta", "framework-policy")
20 for _, i := range []string{"apparmor", "seccomp"} {
21 for _, j := range []string{"policygroups", "templates"} {
22- if err := iterOp(op, filepath.Join(pol, i, j, "*"), filepath.Join(SecBase, i, j), pkgName+"_"); err != nil {
23+ if err := iterOp(op, filepath.Join(pol, i, j, "*"), filepath.Join(rootDir, SecBase, i, j), pkgName+"_"); err != nil {
24 return err
25 }
26 }
27@@ -119,14 +119,14 @@
28
29 // Install sets up the framework's policy from the given snap that's
30 // installed in the given path.
31-func Install(pkgName string, instPath string) error {
32- return frameworkOp(install, pkgName, instPath)
33+func Install(pkgName, instPath, rootDir string) error {
34+ return frameworkOp(install, pkgName, instPath, rootDir)
35 }
36
37 // Remove cleans up the framework's policy from the given snap that's
38 // installed in the given path.
39-func Remove(pkgName string, instPath string) error {
40- return frameworkOp(remove, pkgName, instPath)
41+func Remove(pkgName, instPath, rootDir string) error {
42+ return frameworkOp(remove, pkgName, instPath, rootDir)
43 }
44
45 func aaUp(old, new, dir, pfx string) map[string]bool {
46
47=== modified file 'policy/policy_test.go'
48--- policy/policy_test.go 2015-06-02 20:53:10 +0000
49+++ policy/policy_test.go 2015-06-12 03:58:44 +0000
50@@ -26,8 +26,9 @@
51 "path/filepath"
52 "testing"
53
54+ "sort"
55+
56 . "gopkg.in/check.v1"
57- "sort"
58 )
59
60 // Hook up check.v1 into the "go test" runner.
61@@ -140,13 +141,14 @@
62 }
63
64 func (s *policySuite) TestFrameworkRoundtrip(c *C) {
65+ rootDir := c.MkDir()
66 SecBase = s.dest
67- c.Check(Install("foo", s.orig), IsNil)
68+ c.Check(Install("foo", s.orig, rootDir), IsNil)
69 // check the files were copied, with the packagename prepended properly
70- g, err := filepath.Glob(filepath.Join(SecBase, "*", "*", "foo_*"))
71+ g, err := filepath.Glob(filepath.Join(rootDir, SecBase, "*", "*", "foo_*"))
72 c.Check(err, IsNil)
73 c.Check(g, HasLen, 4*3)
74- c.Check(Remove("foo", s.orig), IsNil)
75+ c.Check(Remove("foo", s.orig, rootDir), IsNil)
76 g, err = filepath.Glob(filepath.Join(SecBase, "*", "*", "*"))
77 c.Check(err, IsNil)
78 c.Check(g, HasLen, 0)
79@@ -155,7 +157,7 @@
80 func (s *policySuite) TestFrameworkError(c *C) {
81 // check we get errors from the iterOp, is all
82 SecBase = s.dest
83- c.Check(frameworkOp(42, "foo", s.orig), ErrorMatches, ".*unknown operation.*")
84+ c.Check(frameworkOp(42, "foo", s.orig, ""), ErrorMatches, ".*unknown operation.*")
85 }
86
87 func (s *policySuite) TestOpString(c *C) {
88
89=== modified file 'snappy/snapp.go'
90--- snappy/snapp.go 2015-06-09 19:11:54 +0000
91+++ snappy/snapp.go 2015-06-12 03:58:44 +0000
92@@ -939,7 +939,7 @@
93 }
94
95 if s.Type() == pkg.TypeFramework {
96- if err := policy.Install(s.Name(), s.basedir); err != nil {
97+ if err := policy.Install(s.Name(), s.basedir, globalRootDir); err != nil {
98 return err
99 }
100 }
101@@ -1001,7 +1001,7 @@
102 }
103
104 if s.Type() == pkg.TypeFramework {
105- if err := policy.Remove(s.Name(), s.basedir); err != nil {
106+ if err := policy.Remove(s.Name(), s.basedir, globalRootDir); err != nil {
107 return err
108 }
109 }

Subscribers

People subscribed via source and target branches