interfaces/mount: add function for parsing fstab-like file #3103

Merged
merged 3 commits into from Mar 31, 2017

Conversation

Projects
None yet
3 participants
Contributor

zyga commented Mar 29, 2017

This is stacked on top of #3102. The new thing is the 2nd commit with a function for parsing a fstab-like file.

zyga added some commits Mar 29, 2017

interfaces/mount: add function for loading fstab-like files
This patch adds a simple function that consumes a reader and parses each
line to a mount.Entry. A set of simple tests is added for completeness.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/mount/entry.go
+ scanner := bufio.NewScanner(reader)
+ for scanner.Scan() {
+ s := strings.TrimSpace(scanner.Text())
+ if i := strings.Index(s, "#"); i != -1 {
@chipaca

chipaca Mar 30, 2017

Member

suggest using IndexByte directly

@zyga

zyga Mar 30, 2017

Contributor

Nice simplification, I didn't know about IndexByte. Done.

interfaces/mount/entry.go
+ s := strings.TrimSpace(scanner.Text())
+ if i := strings.Index(s, "#"); i != -1 {
+ s = strings.TrimSpace(s[0:i])
+ }
@chipaca

chipaca Mar 30, 2017

Member

to me at least it'd make more sense if you trimmed the comment first, and trimmed the space second. Like

s := scanner.Text()
if i := strings.IndexByte(s, '#') {
    s = s[:i]
}
s = strings.TrimSpace(s)
@zyga

zyga Mar 30, 2017

Contributor

Applied.

interfaces/mount: simplify stripping comments
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Contributor

morphis commented Mar 31, 2017

LGTM

@zyga zyga merged commit d54164a into snapcore:master Mar 31, 2017

1 of 6 checks passed

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

@zyga zyga deleted the zyga:load-fstab-file branch Mar 31, 2017

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