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
|
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) {
|
func (mounter *Mounter) GetMountRefs(pathname string) ([]string, error) {
|
||||||
if _, err := os.Stat(normalizeWindowsPath(pathname)); os.IsNotExist(err) {
|
if _, err := os.Stat(normalizeWindowsPath(pathname)); os.IsNotExist(err) {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
refs, err := getAllParentLinks(normalizeWindowsPath(pathname))
|
return []string{pathname}, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return refs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that on windows, it always returns 0. We actually don't set FSGroup on
|
// 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
|
// this func must run in admin mode, otherwise it will fail
|
||||||
func TestGetMountRefs(t *testing.T) {
|
func TestGetMountRefs(t *testing.T) {
|
||||||
fm := &FakeMounter{MountPoints: []MountPoint{}}
|
tests := []struct {
|
||||||
mountPath := `c:\secondmountpath`
|
mountPath string
|
||||||
expectedRefs := []string{`c:\`, `c:\firstmountpath`, mountPath}
|
expectedRefs []string
|
||||||
|
}{
|
||||||
// remove symbolic links first
|
{
|
||||||
for i := 1; i < len(expectedRefs); i++ {
|
mountPath: `c:\windows`,
|
||||||
removeLink(expectedRefs[i])
|
expectedRefs: []string{`c:\windows`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
mountPath: `c:\doesnotexist`,
|
||||||
|
expectedRefs: []string{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// create symbolic links
|
mounter := Mounter{"fake/path"}
|
||||||
for i := 1; i < len(expectedRefs); i++ {
|
|
||||||
if err := makeLink(expectedRefs[i], expectedRefs[i-1]); err != nil {
|
|
||||||
t.Errorf("makeLink failed: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if refs, err := fm.GetMountRefs(mountPath); err != nil || !setEquivalent(expectedRefs, refs) {
|
for _, test := range tests {
|
||||||
t.Errorf("getMountRefs(%q) = %v, error: %v; expected %v", mountPath, refs, err, expectedRefs)
|
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)
|
||||||
|
|
||||||
// remove symbolic links
|
|
||||||
for i := 1; i < len(expectedRefs); i++ {
|
|
||||||
if err := removeLink(expectedRefs[i]); err != nil {
|
|
||||||
t.Errorf("removeLink failed: %v", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue