Skip to content

Commit

Permalink
Merge pull request #69079 from andyzhangx/automated-cherry-pick-of-#6…
Browse files Browse the repository at this point in the history
…8608-upstream-release-1.11

Automated cherry pick of #68608: fix UnmountDevice failure on Windows
  • Loading branch information
k8s-ci-robot committed Oct 4, 2018
2 parents cd15c28 + c87374b commit cd6e3ae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
18 changes: 10 additions & 8 deletions pkg/util/mount/mount_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ func (mounter *Mounter) Unmount(target string) error {
return nil
}

// GetMountRefs finds all other references to the device(drive) referenced
// by mountPath; returns a list of paths.
// GetMountRefs : empty implementation here since there is no place to query all mount points on Windows
func GetMountRefs(mounter Interface, mountPath string) ([]string, error) {
refs, err := getAllParentLinks(normalizeWindowsPath(mountPath))
if err != nil {
if _, err := os.Stat(normalizeWindowsPath(mountPath)); os.IsNotExist(err) {
return []string{}, nil
} else if err != nil {
return nil, err
}
return refs, nil
return []string{mountPath}, nil
}

// List returns a list of all mounted filesystems. todo
Expand Down Expand Up @@ -463,12 +463,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) {
realpath, err := filepath.EvalSymlinks(pathname)
if err != nil {
if _, err := os.Stat(normalizeWindowsPath(pathname)); os.IsNotExist(err) {
return []string{}, nil
} else if err != nil {
return nil, err
}
return getMountRefsByDev(mounter, realpath)
return []string{pathname}, nil
}

// Note that on windows, it always returns 0. We actually don't set FSGroup on
Expand Down
38 changes: 16 additions & 22 deletions pkg/util/mount/mount_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,30 +111,24 @@ 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])
}

// 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)
}
}

if refs, err := GetMountRefs(fm, mountPath); err != nil || !setEquivalent(expectedRefs, refs) {
t.Errorf("getMountRefs(%q) = %v, error: %v; expected %v", mountPath, refs, err, expectedRefs)
tests := []struct {
mountPath string
expectedRefs []string
}{
{
mountPath: `c:\windows`,
expectedRefs: []string{`c:\windows`},
},
{
mountPath: `c:\doesnotexist`,
expectedRefs: []string{},
},
}

// remove symbolic links
for i := 1; i < len(expectedRefs); i++ {
if err := removeLink(expectedRefs[i]); err != nil {
t.Errorf("removeLink failed: %v", err)
mounter := Mounter{"fake/path"}
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)
}
}
}
Expand Down

0 comments on commit cd6e3ae

Please sign in to comment.