mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
fix: adopt go1.23 behavior change in mount point parsing on Windows
fix comments
This commit is contained in:
parent
3ec9c7f4d2
commit
bb49a05fb5
@ -90,7 +90,7 @@ func MkdirAllWithPathCheck(path string, perm os.FileMode) error {
|
||||
// 1. for Unix/Linux OS, check if the path is directory.
|
||||
// 2. for windows NTFS, check if the path is symlink instead of directory.
|
||||
if dir.IsDir() ||
|
||||
(runtime.GOOS == "windows" && (dir.Mode()&os.ModeSymlink != 0)) {
|
||||
(runtime.GOOS == "windows" && (dir.Mode()&os.ModeSymlink != 0 || dir.Mode()&os.ModeIrregular != 0)) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("path %v exists but is not a directory", path)
|
||||
|
@ -85,6 +85,11 @@ func diskUsage(currPath string, info os.FileInfo) (int64, error) {
|
||||
return size, nil
|
||||
}
|
||||
|
||||
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
|
||||
if info.Mode()&os.ModeIrregular != 0 {
|
||||
return size, nil
|
||||
}
|
||||
|
||||
size += info.Size()
|
||||
|
||||
if !info.IsDir() {
|
||||
|
@ -208,6 +208,12 @@ func lockAndCheckSubPathWithoutSymlink(volumePath, subPath string) ([]uintptr, e
|
||||
break
|
||||
}
|
||||
|
||||
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
|
||||
if stat.Mode()&os.ModeIrregular != 0 {
|
||||
errorResult = fmt.Errorf("subpath %q is an unexpected irregular file after EvalSymlinks", currentFullPath)
|
||||
break
|
||||
}
|
||||
|
||||
if !mount.PathWithinBase(currentFullPath, volumePath) {
|
||||
errorResult = fmt.Errorf("SubPath %q not within volume path %q", currentFullPath, volumePath)
|
||||
break
|
||||
@ -342,6 +348,10 @@ func doSafeMakeDir(pathname string, base string, perm os.FileMode) error {
|
||||
if stat.Mode()&os.ModeSymlink != 0 {
|
||||
return fmt.Errorf("subpath %q is an unexpected symlink after Mkdir", currentPath)
|
||||
}
|
||||
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
|
||||
if stat.Mode()&os.ModeIrregular != 0 {
|
||||
return fmt.Errorf("subpath %q is an unexpected irregular file after Mkdir", currentPath)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/mount-utils"
|
||||
@ -232,7 +233,7 @@ func (v VolumePathHandler) RemoveMapPath(mapPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsSymlinkExist returns true if specified file exists and the type is symbolik link.
|
||||
// IsSymlinkExist returns true if specified file exists and the type is symbolik link or irregular file on Windows.
|
||||
// If file doesn't exist, or file exists but not symbolic link, return false with no error.
|
||||
// On other cases, return false with error from Lstat().
|
||||
func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
|
||||
@ -249,6 +250,10 @@ func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
|
||||
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||
return true, nil
|
||||
}
|
||||
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
|
||||
if (runtime.GOOS == "windows") && (fi.Mode()&os.ModeIrregular != 0) {
|
||||
return true, nil
|
||||
}
|
||||
// If file exits but it's not symbolic link, return false and no error
|
||||
return false, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user