mirror of
https://github.com/lima-vm/lima.git
synced 2026-10-28 11:44:35 +08:00
For IsNFS check all parent directories up to the root until one exist
Signed-off-by: Jan Dubois <jan.dubois@suse.com>
This commit is contained in:
1 parent
ba5409441b
commit
58fc7a8b87
2 files changed
+18
-6
No files matched your search
@@ -131,12 +131,6 @@ func newApp() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Make sure that directory is on a local filesystem, not on NFS
|
||||
// if the directory does not yet exist, check the home directory
|
||||
_, err = os.Stat(dir)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
dir = filepath.Dir(dir)
|
||||
}
|
||||
nfs, err := fsutil.IsNFS(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,10 +4,28 @@
|
||||
package fsutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// IsNFS checks if the path is on NFS. If the path does not exist yet, it will walk
|
||||
// up parent directories until one exists, or it hits '/' or '.'.
|
||||
// Any other stat errors will cause IsNFS to fail.
|
||||
func IsNFS(path string) (bool, error) {
|
||||
for len(path) > 1 {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return false, err
|
||||
}
|
||||
path = filepath.Dir(path)
|
||||
}
|
||||
|
||||
var sf unix.Statfs_t
|
||||
if err := unix.Statfs(path, &sf); err != nil {
|
||||
return false, err
|
||||
|
||||
Reference in new issue
Block a user