Make mount.Mounted() capable of handling files

The function `fileutils.ReadSymlinkedDirectory` makes `mount.Mounted()`
fail if the mount is a file. We now only check that if the mount is a
directory to allow handling files in `mount.Mounted()`.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
This commit is contained in:
Sascha Grunert 2020-03-13 11:40:12 +01:00
parent 19256fe26b
commit 90513cbb96
No known key found for this signature in database
GPG Key ID: 8CE029DD1A866E52
1 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package mount
import (
"os"
"sort"
"strconv"
"strings"
@ -56,10 +57,17 @@ func Mounted(mountpoint string) (bool, error) {
return false, err
}
mountpoint, err = fileutils.ReadSymlinkedDirectory(mountpoint)
info, err := os.Stat(mountpoint)
if err != nil {
return false, err
}
if info.IsDir() {
mountpoint, err = fileutils.ReadSymlinkedDirectory(mountpoint)
if err != nil {
return false, err
}
}
// Search the table for the mountpoint
for _, e := range entries {
if e.Mountpoint == mountpoint {