Skip to content

Commit 9eac70a

Browse files
committed
For IsNFS check all parent directories up to the root until one exist
Signed-off-by: Jan Dubois <jan.dubois@suse.com>
1 parent ba54094 commit 9eac70a

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

cmd/limactl/main.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ func newApp() *cobra.Command {
131131
if err != nil {
132132
return err
133133
}
134-
// Make sure that directory is on a local filesystem, not on NFS
135-
// if the directory does not yet exist, check the home directory
136-
_, err = os.Stat(dir)
137-
if errors.Is(err, os.ErrNotExist) {
138-
dir = filepath.Dir(dir)
139-
}
140134
nfs, err := fsutil.IsNFS(dir)
141135
if err != nil {
142136
return err

pkg/fsutil/fsutil_linux.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@
44
package fsutil
55

66
import (
7+
"errors"
8+
"os"
9+
"path/filepath"
10+
711
"golang.org/x/sys/unix"
812
)
913

14+
// IsNFS checks if the path is on NFS. If the path does not exist yet, it will walk
15+
// up parent directories until one exists, or it hits the root of the volume.
16+
// Any other stat errors will cause IsNFS to fail.
1017
func IsNFS(path string) (bool, error) {
18+
for len(path) > len(filepath.VolumeName(path))+1 {
19+
_, err := os.Stat(path)
20+
if !errors.Is(err, os.ErrNotExist) {
21+
break
22+
}
23+
path = filepath.Dir(path)
24+
}
25+
1126
var sf unix.Statfs_t
1227
if err := unix.Statfs(path, &sf); err != nil {
1328
return false, err

0 commit comments

Comments
 (0)