Skip to content

Commit 87defb5

Browse files
authored
Merge pull request kubernetes#129242 from tallclair/windows-mkdir
[windows] Don't chmod existing directory in MkdirAll
2 parents f422a58 + a7340ff commit 87defb5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/util/filesystem/util_windows.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,21 @@ func IsUnixDomainSocket(filePath string) (bool, error) {
9494
// permissions once the directory is created.
9595
func MkdirAll(path string, perm os.FileMode) error {
9696
klog.V(6).InfoS("Function MkdirAll starts", "path", path, "perm", perm)
97+
if _, err := os.Stat(path); err == nil {
98+
// Path already exists: nothing to do.
99+
return nil
100+
} else if !os.IsNotExist(err) {
101+
return fmt.Errorf("error checking path %s: %w", path, err)
102+
}
103+
97104
err := os.MkdirAll(path, perm)
98105
if err != nil {
99-
return fmt.Errorf("Error creating directory %s: %v", path, err)
106+
return fmt.Errorf("error creating directory %s: %w", path, err)
100107
}
101108

102109
err = Chmod(path, perm)
103110
if err != nil {
104-
return fmt.Errorf("Error setting permissions for directory %s: %v", path, err)
111+
return fmt.Errorf("error setting permissions for directory %s: %w", path, err)
105112
}
106113

107114
return nil

0 commit comments

Comments
 (0)