Skip to content

Commit

Permalink
dirs,overlord: drop RawSnapMountDir and strip prefix instead
Browse files Browse the repository at this point in the history
  • Loading branch information
morphis committed May 17, 2017
1 parent 2f3b287 commit 9b771dd
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 152 deletions.
13 changes: 4 additions & 9 deletions dirs/dirs.go
Expand Up @@ -33,9 +33,6 @@ var (
GlobalRootDir string

SnapMountDir string
// RawSnapMountDir is the path of the snap mount dir without
// the GlobalRootDir as prefix.
RawSnapMountDir string

// CoreSnapMountDir is the path of the snap mount dir inside
// the snap confinement environment. Give this nature it will
Expand All @@ -44,8 +41,8 @@ var (

// CoreLibExecDir is similar to CoreSnapMountDir but for the
// LibExecDir used by snapd.
CoreLibExecDir string
DistroLibExecDir string
CoreLibExecDir string
DistroLibExecDir string

SnapBlobDir string
SnapDataDir string
Expand Down Expand Up @@ -138,11 +135,9 @@ func SetRootDir(rootdir string) {

switch release.ReleaseInfo.ID {
case "fedora", "centos", "rhel", "arch":
RawSnapMountDir = "/var/lib/snapd/snap"
SnapMountDir = filepath.Join(rootdir, RawSnapMountDir)
SnapMountDir = filepath.Join(rootdir, "/var/lib/snapd/snap")
default:
RawSnapMountDir = defaultSnapMountDir
SnapMountDir = filepath.Join(rootdir, RawSnapMountDir)
SnapMountDir = filepath.Join(rootdir, defaultSnapMountDir)
}

SnapDataDir = filepath.Join(rootdir, "/var/snap")
Expand Down
10 changes: 5 additions & 5 deletions overlord/managers_test.go
Expand Up @@ -200,10 +200,10 @@ apps:
c.Assert(osutil.FileExists(filepath.Join(dirs.SnapBlobDir, "foo_x1.snap")), Equals, true)

// ensure the right unit is created
mup := systemd.MountUnitPath(filepath.Join(dirs.RawSnapMountDir, "foo/x1"))
mup := systemd.MountUnitPath(filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "foo/x1"))
content, err := ioutil.ReadFile(mup)
c.Assert(err, IsNil)
c.Assert(string(content), Matches, fmt.Sprintf("(?ms).*^Where=%s/foo/x1", dirs.RawSnapMountDir))
c.Assert(string(content), Matches, fmt.Sprintf("(?ms).*^Where=%s/foo/x1", dirs.StripRootDir(dirs.SnapMountDir)))
c.Assert(string(content), Matches, "(?ms).*^What=/var/lib/snapd/snaps/foo_x1.snap")

}
Expand Down Expand Up @@ -242,7 +242,7 @@ apps:

// snap file and its mount
c.Assert(osutil.FileExists(filepath.Join(dirs.SnapBlobDir, "foo_x1.snap")), Equals, false)
mup := systemd.MountUnitPath(filepath.Join(dirs.RawSnapMountDir, "foo/x1"))
mup := systemd.MountUnitPath(filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "foo/x1"))
c.Assert(osutil.FileExists(mup), Equals, false)
}

Expand Down Expand Up @@ -634,10 +634,10 @@ apps:
c.Assert(osutil.FileExists(filepath.Join(dirs.SnapBlobDir, "foo_55.snap")), Equals, true)

// ensure the right unit is created
mup := systemd.MountUnitPath(filepath.Join(dirs.RawSnapMountDir, "foo/55"))
mup := systemd.MountUnitPath(filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "foo/55"))
content, err := ioutil.ReadFile(mup)
c.Assert(err, IsNil)
c.Assert(string(content), Matches, fmt.Sprintf("(?ms).*^Where=%s/foo/55", dirs.RawSnapMountDir))
c.Assert(string(content), Matches, fmt.Sprintf("(?ms).*^Where=%s/foo/55", dirs.StripRootDir(dirs.SnapMountDir)))
c.Assert(string(content), Matches, "(?ms).*^What=/var/lib/snapd/snaps/foo_55.snap")
}

Expand Down
6 changes: 3 additions & 3 deletions overlord/snapstate/backend/mountunit_test.go
Expand Up @@ -76,7 +76,7 @@ func (s *mountunitSuite) TestAddMountUnit(c *C) {
c.Assert(err, IsNil)

// ensure correct mount unit
un := fmt.Sprintf("%s.mount", systemd.EscapeUnitNamePath(filepath.Join(dirs.RawSnapMountDir, "foo", "13")))
un := fmt.Sprintf("%s.mount", systemd.EscapeUnitNamePath(filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "foo", "13")))
mount, err := ioutil.ReadFile(filepath.Join(dirs.SnapServicesDir, un))
c.Assert(err, IsNil)
c.Assert(string(mount), Equals, fmt.Sprintf(`[Unit]
Expand All @@ -90,7 +90,7 @@ Options=nodev,ro
[Install]
WantedBy=multi-user.target
`, dirs.RawSnapMountDir))
`, dirs.StripRootDir(dirs.SnapMountDir)))

}

Expand All @@ -108,7 +108,7 @@ func (s *mountunitSuite) TestRemoveMountUnit(c *C) {
c.Assert(err, IsNil)

// ensure we have the files
un := fmt.Sprintf("%s.mount", systemd.EscapeUnitNamePath(filepath.Join(dirs.RawSnapMountDir, "foo", "13")))
un := fmt.Sprintf("%s.mount", systemd.EscapeUnitNamePath(filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "foo", "13")))
p := filepath.Join(dirs.SnapServicesDir, un)
c.Assert(osutil.FileExists(p), Equals, true)

Expand Down
4 changes: 2 additions & 2 deletions overlord/snapstate/backend/setup_test.go
Expand Up @@ -83,10 +83,10 @@ func (s *setupSuite) TestSetupDoUndoSimple(c *C) {
c.Assert(osutil.FileExists(filepath.Join(dirs.SnapBlobDir, "hello_14.snap")), Equals, true)

// ensure the right unit is created
mup := systemd.MountUnitPath(filepath.Join(dirs.RawSnapMountDir, "hello/14"))
mup := systemd.MountUnitPath(filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "hello/14"))
content, err := ioutil.ReadFile(mup)
c.Assert(err, IsNil)
c.Assert(string(content), Matches, fmt.Sprintf("(?ms).*^Where=%s", filepath.Join(dirs.RawSnapMountDir, "hello/14")))
c.Assert(string(content), Matches, fmt.Sprintf("(?ms).*^Where=%s", filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "hello/14")))
c.Assert(string(content), Matches, "(?ms).*^What=/var/lib/snapd/snaps/hello_14.snap")

minInfo := snap.MinimalPlaceInfo("hello", snap.R(14))
Expand Down
6 changes: 3 additions & 3 deletions overlord/snapstate/handlers_link_test.go
Expand Up @@ -159,7 +159,7 @@ func (s *linkSnapSuite) TestDoLinkSnapTryToCleanupOnError(c *C) {
Channel: "beta",
})

s.fakeBackend.linkSnapFailTrigger = filepath.Join(dirs.RawSnapMountDir, "foo/35")
s.fakeBackend.linkSnapFailTrigger = filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "foo/35")
s.state.NewChange("dummy", "...").AddTask(t)
s.state.Unlock()

Expand All @@ -181,11 +181,11 @@ func (s *linkSnapSuite) TestDoLinkSnapTryToCleanupOnError(c *C) {
},
{
op: "link-snap.failed",
name: filepath.Join(dirs.RawSnapMountDir, "foo/35"),
name: filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "foo/35"),
},
{
op: "unlink-snap",
name: filepath.Join(dirs.RawSnapMountDir, "foo/35"),
name: filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "foo/35"),
},
})
}
Expand Down
4 changes: 2 additions & 2 deletions overlord/snapstate/handlers_mount_test.go
Expand Up @@ -131,7 +131,7 @@ func (s *mountSnapSuite) TestDoUndoMountSnap(c *C) {
c.Check(s.fakeBackend.ops, DeepEquals, fakeOps{
{
op: "current",
old: filepath.Join(dirs.RawSnapMountDir, "core/1"),
old: filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "core/1"),
},
{
op: "setup-snap",
Expand All @@ -140,7 +140,7 @@ func (s *mountSnapSuite) TestDoUndoMountSnap(c *C) {
},
{
op: "undo-setup-snap",
name: filepath.Join(dirs.RawSnapMountDir, "core/2"),
name: filepath.Join(dirs.StripRootDir(dirs.SnapMountDir), "core/2"),
stype: "os",
},
})
Expand Down

0 comments on commit 9b771dd

Please sign in to comment.