Skip to content

Commit

Permalink
cmd/snap-update-ns: pass MountProfileUpdate to apply{System,User}Fstab
Browse files Browse the repository at this point in the history
This allows some de-duplication of passed arguments.
The final simplification will come after applySystemFstab merges with
computeAndSaveSystemChanges since that's the last holdout for the
extra, redundant arguments.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
  • Loading branch information
zyga committed Apr 17, 2019
1 parent e2c9d7c commit 1ffaae4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
8 changes: 5 additions & 3 deletions cmd/snap-update-ns/main.go
Expand Up @@ -78,9 +78,11 @@ func run() error {
if err := parseArgs(os.Args[1:]); err != nil {
return err
}

var ctx MountProfileUpdateContext
if opts.UserMounts {
return applyUserFstab(opts.Positionals.SnapName)
ctx = NewUserProfileUpdateContext(opts.Positionals.SnapName, opts.FromSnapConfine, os.Getuid())
return applyUserFstab(ctx, opts.Positionals.SnapName)
}
return applySystemFstab(opts.Positionals.SnapName, opts.FromSnapConfine)
ctx = NewSystemProfileUpdateContext(opts.Positionals.SnapName, opts.FromSnapConfine)
return applySystemFstab(ctx, opts.Positionals.SnapName)
}
3 changes: 2 additions & 1 deletion cmd/snap-update-ns/main_test.go
Expand Up @@ -381,7 +381,8 @@ func (s *mainSuite) TestApplyUserFstab(c *C) {
err = ioutil.WriteFile(desiredProfilePath, []byte(desiredProfileContent), 0644)
c.Assert(err, IsNil)

err = update.ApplyUserFstab("foo")
ctx := update.NewUserProfileUpdateContext(snapName, true, 1000)
err = update.ApplyUserFstab(ctx, "foo")
c.Assert(err, IsNil)

xdgRuntimeDir := fmt.Sprintf("%s/%d", dirs.XdgRuntimeDirBase, os.Getuid())
Expand Down
3 changes: 1 addition & 2 deletions cmd/snap-update-ns/system.go
Expand Up @@ -76,8 +76,7 @@ func (ctx *SystemProfileUpdateContext) Assumptions() *Assumptions {
return as
}

func applySystemFstab(instanceName string, fromSnapConfine bool) error {
ctx := NewSystemProfileUpdateContext(instanceName, fromSnapConfine)
func applySystemFstab(ctx MountProfileUpdateContext, instanceName string) error {

This comment has been minimized.

Copy link
@chipaca

chipaca Apr 26, 2019

nice

unlock, err := ctx.Lock()
if err != nil {
return err
Expand Down
9 changes: 3 additions & 6 deletions cmd/snap-update-ns/user.go
Expand Up @@ -21,7 +21,6 @@ package main

import (
"fmt"
"os"

"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/osutil"
Expand Down Expand Up @@ -79,16 +78,14 @@ func (ctx *UserProfileUpdateContext) LoadDesiredProfile() (*osutil.MountProfile,
return profile, nil
}

func applyUserFstab(snapName string) error {
fromSnapConfine := true // currently always true, no persistence yet.
ctx := NewUserProfileUpdateContext(snapName, fromSnapConfine, os.Getuid())
func applyUserFstab(ctx MountProfileUpdateContext, instanceName string) error {

This comment has been minimized.

Copy link
@chipaca

chipaca Apr 26, 2019

and, nice

desired, err := ctx.LoadDesiredProfile()
if err != nil {
return fmt.Errorf("cannot load desired user mount profile of snap %q: %s", snapName, err)
return fmt.Errorf("cannot load desired user mount profile of snap %q: %s", instanceName, err)
}
debugShowProfile(desired, "desired mount profile")
as := ctx.Assumptions()
_, err = applyProfile(ctx, snapName, &osutil.MountProfile{}, desired, as)
_, err = applyProfile(ctx, instanceName, &osutil.MountProfile{}, desired, as)
return err
}

Expand Down

0 comments on commit 1ffaae4

Please sign in to comment.