Skip to content

Commit 876fe29

Browse files
authored
Merge pull request #3835 from jandubois/nfs-check
For IsNFS check all parent directories up to the root until one exist
2 parents 5efb04b + 58fc7a8 commit 876fe29

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
@@ -134,12 +134,6 @@ func newApp() *cobra.Command {
134134
if err != nil {
135135
return err
136136
}
137-
// Make sure that directory is on a local filesystem, not on NFS
138-
// if the directory does not yet exist, check the home directory
139-
_, err = os.Stat(dir)
140-
if errors.Is(err, os.ErrNotExist) {
141-
dir = filepath.Dir(dir)
142-
}
143137
nfs, err := fsutil.IsNFS(dir)
144138
if err != nil {
145139
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)