Skip to content

Commit b84cb65

Browse files
authored
Merge pull request kubernetes#129370 from andyzhangx/adopt-go1.23-behavior-change
fix: adopt go1.23 behavior change in mount point parsing on Windows#2
2 parents 6025e23 + bb49a05 commit b84cb65

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

pkg/util/filesystem/defaultfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func MkdirAllWithPathCheck(path string, perm os.FileMode) error {
9090
// 1. for Unix/Linux OS, check if the path is directory.
9191
// 2. for windows NTFS, check if the path is symlink instead of directory.
9292
if dir.IsDir() ||
93-
(runtime.GOOS == "windows" && (dir.Mode()&os.ModeSymlink != 0)) {
93+
(runtime.GOOS == "windows" && (dir.Mode()&os.ModeSymlink != 0 || dir.Mode()&os.ModeIrregular != 0)) {
9494
return nil
9595
}
9696
return fmt.Errorf("path %v exists but is not a directory", path)

pkg/volume/util/fs/fs_windows.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func diskUsage(currPath string, info os.FileInfo) (int64, error) {
8585
return size, nil
8686
}
8787

88+
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
89+
if info.Mode()&os.ModeIrregular != 0 {
90+
return size, nil
91+
}
92+
8893
size += info.Size()
8994

9095
if !info.IsDir() {

pkg/volume/util/subpath/subpath_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ func lockAndCheckSubPathWithoutSymlink(volumePath, subPath string) ([]uintptr, e
201201
break
202202
}
203203

204+
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
205+
if stat.Mode()&os.ModeIrregular != 0 {
206+
errorResult = fmt.Errorf("subpath %q is an unexpected irregular file after EvalSymlinks", currentFullPath)
207+
break
208+
}
209+
204210
if !mount.PathWithinBase(currentFullPath, volumePath) {
205211
errorResult = fmt.Errorf("SubPath %q not within volume path %q", currentFullPath, volumePath)
206212
break
@@ -335,6 +341,10 @@ func doSafeMakeDir(pathname string, base string, perm os.FileMode) error {
335341
if stat.Mode()&os.ModeSymlink != 0 {
336342
return fmt.Errorf("subpath %q is an unexpected symlink after Mkdir", currentPath)
337343
}
344+
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
345+
if stat.Mode()&os.ModeIrregular != 0 {
346+
return fmt.Errorf("subpath %q is an unexpected irregular file after Mkdir", currentPath)
347+
}
338348
}
339349

340350
return nil

pkg/volume/util/volumepathhandler/volume_path_handler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"path/filepath"
23+
"runtime"
2324

2425
"k8s.io/klog/v2"
2526
"k8s.io/mount-utils"
@@ -232,7 +233,7 @@ func (v VolumePathHandler) RemoveMapPath(mapPath string) error {
232233
return nil
233234
}
234235

235-
// IsSymlinkExist returns true if specified file exists and the type is symbolik link.
236+
// IsSymlinkExist returns true if specified file exists and the type is symbolik link or irregular file on Windows.
236237
// If file doesn't exist, or file exists but not symbolic link, return false with no error.
237238
// On other cases, return false with error from Lstat().
238239
func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
@@ -249,6 +250,10 @@ func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
249250
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
250251
return true, nil
251252
}
253+
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
254+
if (runtime.GOOS == "windows") && (fi.Mode()&os.ModeIrregular != 0) {
255+
return true, nil
256+
}
252257
// If file exits but it's not symbolic link, return false and no error
253258
return false, nil
254259
}

0 commit comments

Comments
 (0)