Skip to content

Commit

Permalink
Merge pull request #10992 from MiguelPires/fix-snap-perm
Browse files Browse the repository at this point in the history
cmd: create ~/snap dir with 0700 perms
  • Loading branch information
mvo5 committed Nov 12, 2021
2 parents 5b6f77a + 35d5f44 commit 7d2a966
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/snap/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ func createUserDataDirs(info *snap.Info) error {
return fmt.Errorf(i18n.G("cannot get the current user: %v"), err)
}

snapDir := filepath.Join(usr.HomeDir, dirs.UserHomeSnapDir)
if err := os.MkdirAll(snapDir, 0700); err != nil {
return fmt.Errorf(i18n.G("cannot create snap home dir: %w"), err)
}
// see snapenv.User
instanceUserData := info.UserDataDir(usr.HomeDir)
instanceCommonUserData := info.UserCommonDataDir(usr.HomeDir)
Expand Down
17 changes: 17 additions & 0 deletions cmd/snap/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,3 +1819,20 @@ func (s *RunSuite) TestWaitWhileInhibitedTextFlow(c *check.C) {
c.Check(meter.Finishes, check.Equals, 1)
c.Check(meter.Labels, check.DeepEquals, []string{"please wait..."})
}

func (s *RunSuite) TestCreateSnapDirPermissions(c *check.C) {
usr, err := user.Current()
c.Assert(err, check.IsNil)

usr.HomeDir = s.fakeHome
snaprun.MockUserCurrent(func() (*user.User, error) {
return usr, nil
})

info := &snap.Info{SuggestedName: "some-snap"}
c.Assert(snaprun.CreateUserDataDirs(info), check.IsNil)

fi, err := os.Stat(filepath.Join(s.fakeHome, dirs.UserHomeSnapDir))
c.Assert(err, check.IsNil)
c.Assert(fi.Mode()&os.ModePerm, check.Equals, os.FileMode(0700))
}

0 comments on commit 7d2a966

Please sign in to comment.