diff options
Diffstat (limited to 'filesystem')
| -rw-r--r-- | filesystem/mountpoint.go | 3 | ||||
| -rw-r--r-- | filesystem/mountpoint_test.go | 32 |
2 files changed, 34 insertions, 1 deletions
diff --git a/filesystem/mountpoint.go b/filesystem/mountpoint.go index d9dbf37..6119be8 100644 --- a/filesystem/mountpoint.go +++ b/filesystem/mountpoint.go @@ -282,7 +282,7 @@ func GetMount(mountpoint string) (*Mount, error) { return mnt, nil } -// getMountsFromLink returns the Mount object which matches the provided link. +// getMountFromLink returns the Mount object which matches the provided link. // This link is formatted as a tag (e.g. <token>=<value>) similar to how they // appear in "/etc/fstab". Currently, only "UUID" tokens are supported. An error // is returned if the link is invalid or we cannot load the required mount data. @@ -290,6 +290,7 @@ func GetMount(mountpoint string) (*Mount, error) { // functions, run UpdateMountInfo to see the change. func getMountFromLink(link string) (*Mount, error) { // Parse the link + link = strings.TrimSpace(link) linkComponents := strings.Split(link, "=") if len(linkComponents) != 2 { return nil, errors.Wrapf(ErrFollowLink, "link %q format is invalid", link) diff --git a/filesystem/mountpoint_test.go b/filesystem/mountpoint_test.go index d21ba48..ad0dab7 100644 --- a/filesystem/mountpoint_test.go +++ b/filesystem/mountpoint_test.go @@ -255,6 +255,38 @@ func TestLoadOnlyBindMounts(t *testing.T) { } } +// Test making a filesystem link (i.e. "UUID=...") and following it, and test +// that leading and trailing whitespace in the link is ignored. +func TestGetMountFromLink(t *testing.T) { + mnt, err := getTestMount(t) + if err != nil { + t.Skip(err) + } + link, err := makeLink(mnt, uuidToken) + if err != nil { + t.Fatal(err) + } + linkedMnt, err := getMountFromLink(link) + if err != nil { + t.Fatal(err) + } + if linkedMnt != mnt { + t.Fatal("Link doesn't point to the same Mount") + } + if linkedMnt, err = getMountFromLink(link + "\n"); err != nil { + t.Fatal(err) + } + if linkedMnt != mnt { + t.Fatal("Link doesn't point to the same Mount") + } + if linkedMnt, err = getMountFromLink(" " + link + " \r\n"); err != nil { + t.Fatal(err) + } + if linkedMnt != mnt { + t.Fatal("Link doesn't point to the same Mount") + } +} + // Benchmarks how long it takes to update the mountpoint data func BenchmarkLoadFirst(b *testing.B) { for n := 0; n < b.N; n++ { |