interfaces/mount: add high-level Profile functions #3135

Merged
merged 2 commits into from Apr 6, 2017

Conversation

Projects
None yet
3 participants
Contributor

zyga commented Apr 4, 2017

This code tweaks earlier functions that operated on []Entry to operate
on *Profile (profile being simply a struct with []Entry field for now).

There are two more functions, one that loads and one that saves a profile
from a given file. Everything is fully tested.

Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com

zyga added some commits Apr 4, 2017

interfaces/mount: add high-level Profile functions
This code tweaks earlier functions that operated on []Entry to operate
on *Profile (profile being simply a struct with []Entry field for now).

There are two more functions, one that loads and one that saves a profile
from a given file. Everything is fully tested.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/mount: correct signature of WriteTo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
+ "github.com/snapcore/snapd/osutil"
+)
+
+// Profile represents an array of mount entries.
@niemeyer

niemeyer Apr 5, 2017

Contributor

Nice!

+}
+
+// Save saves a mount profile (fstab-like) to a given file.
+// The profile is saved with an atomic write+rename+sync operation.
@niemeyer

niemeyer Apr 5, 2017

Contributor

Thanks!

+// ReadProfile reads and parses a mount profile.
+//
+// The supported format is described by fstab(5).
+func ReadProfile(reader io.Reader) (*Profile, error) {
@niemeyer

niemeyer Apr 5, 2017

Contributor

I'm assuming nothing changed below other than moving it.

@zyga

zyga Apr 6, 2017

Contributor

Yes, all the same

+//
+// The supported format is described by fstab(5).
+// Note that there is no support for comments.
+func (p *Profile) WriteTo(writer io.Writer) (int64, error) {
@niemeyer

niemeyer Apr 5, 2017

Contributor

Do we need this? Isn't the use case to write to a file always?

@zyga

zyga Apr 6, 2017

Contributor

I used it to write tests. We don't need it but I'd keep it just because it tests nicely.

chipaca approved these changes Apr 6, 2017

lurvely.

+ if _, err := p.WriteTo(&buf); err != nil {
+ return err
+ }
+ return osutil.AtomicWriteFile(fname, buf.Bytes(), 0600, osutil.AtomicWriteFlags(0))
@chipaca

chipaca Apr 6, 2017

Member

hm. Maybe we want to have osutil.AtomicWriteDefault?

@zyga

zyga Apr 6, 2017

Contributor

As in with 0600 permissions or what?

@zyga zyga merged commit 2da4b43 into snapcore:master Apr 6, 2017

6 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
xenial-amd64 autopkgtest finished (success)
Details
xenial-i386 autopkgtest finished (success)
Details
xenial-ppc64el autopkgtest finished (success)
Details
yakkety-amd64 autopkgtest finished (success)
Details
zesty-amd64 autopkgtest finished (success)
Details

@zyga zyga deleted the zyga:profile-apis branch Apr 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment