diff options
| -rw-r--r-- | systemd/systemd.go | 4 | ||||
| -rw-r--r-- | systemd/systemd_test.go | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/systemd/systemd.go b/systemd/systemd.go index 7bc92a46ca..48ca5f997e 100644 --- a/systemd/systemd.go +++ b/systemd/systemd.go @@ -1429,8 +1429,8 @@ func ensureMountUnitFile(u *MountUnitOptions) (mountUnitName string, modified mo if stateErr == osutil.ErrSameState { modified = mountUnchanged - } else if err != nil { - return "", mountUnchanged, err + } else if stateErr != nil { + return "", mountUnchanged, stateErr } return filepath.Base(mu), modified, nil diff --git a/systemd/systemd_test.go b/systemd/systemd_test.go index f177094f34..93e795417e 100644 --- a/systemd/systemd_test.go +++ b/systemd/systemd_test.go @@ -2411,3 +2411,22 @@ func (s *systemdErrorSuite) TestErrorStringNoSystemctl(c *C) { _, err := Version() c.Check(err, ErrorMatches, `systemctl command \[--version\] failed with: exec: "systemctl": executable file not found in \$PATH`) } + +func (s *systemdErrorSuite) TestEnsureMountUnitFileEnsureFileStateErr(c *C) { + dirs.SetRootDir(c.MkDir()) + defer dirs.SetRootDir("") + + restore := osutil.MockMountInfo("") + defer restore() + + mockSnapPath := filepath.Join(dirs.GlobalRootDir, "/var/lib/snappy/snaps/foo_1.0.snap") + makeMockFile(c, mockSnapPath) + + // trigger an error below by creating a directory with the + // same name as the mount unit file + err := os.MkdirAll(filepath.Join(dirs.GlobalRootDir, "/etc/systemd/system/snap-snapname-123.mount"), 0755) + c.Assert(err, IsNil) + + _, err = New(SystemMode, nil).EnsureMountUnitFile("foo", "42", mockSnapPath, "/snap/snapname/123", "squashfs") + c.Assert(err, ErrorMatches, `rename .*/etc/systemd/system/snap-snapname-123.mount.* .*/etc/systemd/system/snap-snapname-123.mount: file exists`) +} |
