Skip to content

Commit 58fc7a8

Browse files
committed
For IsNFS check all parent directories up to the root until one exist
Signed-off-by: Jan Dubois <[email protected]>
1 parent ba54094 commit 58fc7a8

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,28 @@
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 '/' or '.'.
16+
// Any other stat errors will cause IsNFS to fail.
1017
func IsNFS(path string) (bool, error) {
18+
for len(path) > 1 {
19+
_, err := os.Stat(path)
20+
if err == nil {
21+
break
22+
}
23+
if !errors.Is(err, os.ErrNotExist) {
24+
return false, err
25+
}
26+
path = filepath.Dir(path)
27+
}
28+
1129
var sf unix.Statfs_t
1230
if err := unix.Statfs(path, &sf); err != nil {
1331
return false, err

0 commit comments

Comments
 (0)