mirror of https://github.com/k3s-io/k3s
Merge pull request #68608 from andyzhangx/UnmountDevice-windows
fix UnmountDevice failure on Windowspull/58/head
commit
450fdc9c09
|
@ -458,17 +458,14 @@ func getAllParentLinks(path string) ([]string, error) {
|
|||
return links, nil
|
||||
}
|
||||
|
||||
// GetMountRefs : empty implementation here since there is no place to query all mount points on Windows
|
||||
func (mounter *Mounter) GetMountRefs(pathname string) ([]string, error) {
|
||||
if _, err := os.Stat(normalizeWindowsPath(pathname)); os.IsNotExist(err) {
|
||||
return []string{}, nil
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
refs, err := getAllParentLinks(normalizeWindowsPath(pathname))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return refs, nil
|
||||
return []string{pathname}, nil
|
||||
}
|
||||
|
||||
// Note that on windows, it always returns 0. We actually don't set FSGroup on
|
||||
|
|
|
@ -111,30 +111,25 @@ func setEquivalent(set1, set2 []string) bool {
|
|||
|
||||
// this func must run in admin mode, otherwise it will fail
|
||||
func TestGetMountRefs(t *testing.T) {
|
||||
fm := &FakeMounter{MountPoints: []MountPoint{}}
|
||||
mountPath := `c:\secondmountpath`
|
||||
expectedRefs := []string{`c:\`, `c:\firstmountpath`, mountPath}
|
||||
|
||||
// remove symbolic links first
|
||||
for i := 1; i < len(expectedRefs); i++ {
|
||||
removeLink(expectedRefs[i])
|
||||
tests := []struct {
|
||||
mountPath string
|
||||
expectedRefs []string
|
||||
}{
|
||||
{
|
||||
mountPath: `c:\windows`,
|
||||
expectedRefs: []string{`c:\windows`},
|
||||
},
|
||||
{
|
||||
mountPath: `c:\doesnotexist`,
|
||||
expectedRefs: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
// create symbolic links
|
||||
for i := 1; i < len(expectedRefs); i++ {
|
||||
if err := makeLink(expectedRefs[i], expectedRefs[i-1]); err != nil {
|
||||
t.Errorf("makeLink failed: %v", err)
|
||||
}
|
||||
}
|
||||
mounter := Mounter{"fake/path"}
|
||||
|
||||
if refs, err := fm.GetMountRefs(mountPath); err != nil || !setEquivalent(expectedRefs, refs) {
|
||||
t.Errorf("getMountRefs(%q) = %v, error: %v; expected %v", mountPath, refs, err, expectedRefs)
|
||||
}
|
||||
|
||||
// remove symbolic links
|
||||
for i := 1; i < len(expectedRefs); i++ {
|
||||
if err := removeLink(expectedRefs[i]); err != nil {
|
||||
t.Errorf("removeLink failed: %v", err)
|
||||
for _, test := range tests {
|
||||
if refs, err := mounter.GetMountRefs(test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) {
|
||||
t.Errorf("getMountRefs(%q) = %v, error: %v; expected %v", test.mountPath, refs, err, test.expectedRefs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue