mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30: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.
|
// 1. for Unix/Linux OS, check if the path is directory.
|
||||||
// 2. for windows NTFS, check if the path is symlink instead of directory.
|
// 2. for windows NTFS, check if the path is symlink instead of directory.
|
||||||
if dir.IsDir() ||
|
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 nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("path %v exists but is not a directory", path)
|
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
|
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()
|
size += info.Size()
|
||||||
|
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
|
@ -208,6 +208,12 @@ func lockAndCheckSubPathWithoutSymlink(volumePath, subPath string) ([]uintptr, e
|
|||||||
break
|
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) {
|
if !mount.PathWithinBase(currentFullPath, volumePath) {
|
||||||
errorResult = fmt.Errorf("SubPath %q not within volume path %q", currentFullPath, volumePath)
|
errorResult = fmt.Errorf("SubPath %q not within volume path %q", currentFullPath, volumePath)
|
||||||
break
|
break
|
||||||
@ -342,6 +348,10 @@ func doSafeMakeDir(pathname string, base string, perm os.FileMode) error {
|
|||||||
if stat.Mode()&os.ModeSymlink != 0 {
|
if stat.Mode()&os.ModeSymlink != 0 {
|
||||||
return fmt.Errorf("subpath %q is an unexpected symlink after Mkdir", currentPath)
|
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
|
return nil
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/mount-utils"
|
"k8s.io/mount-utils"
|
||||||
@ -232,7 +233,7 @@ func (v VolumePathHandler) RemoveMapPath(mapPath string) error {
|
|||||||
return nil
|
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.
|
// 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().
|
// On other cases, return false with error from Lstat().
|
||||||
func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
|
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 {
|
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||||
return true, nil
|
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
|
// If file exits but it's not symbolic link, return false and no error
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user