Skip to content

Commit

Permalink
cleanup: windows functions
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx committed Dec 11, 2024
1 parent 05d6c8d commit efcd49e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
1 change: 1 addition & 0 deletions deploy/example/windows/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ metadata:
app: busybox
spec:
serviceName: statefulset-azurefile-win
podManagementPolicy: Parallel # default is OrderedReady
replicas: 1
template:
metadata:
Expand Down
4 changes: 2 additions & 2 deletions pkg/mounter/safe_mounter_host_process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (mounter *winMounter) SMBMount(source, target, fsType string, mountOptions,

// Mount just creates a soft link at target pointing to source.
func (mounter *winMounter) Mount(source, target, fstype string, options []string) error {
return filesystem.LinkPath(normalizeWindowsPath(source), normalizeWindowsPath(target))
return os.Symlink(normalizeWindowsPath(source), normalizeWindowsPath(target))
}

// Rmdir - delete the given directory
Expand Down Expand Up @@ -191,7 +191,7 @@ func (mounter *winMounter) IsLikelyNotMountPoint(path string) (bool, error) {
// Currently the make dir is only used from the staging code path, hence we call it
// with Plugin context..
func (mounter *winMounter) MakeDir(path string) error {
return filesystem.Mkdir(normalizeWindowsPath(path))
return os.MkdirAll(normalizeWindowsPath(path), 0755)
}

// ExistsPath - Checks if a path exists. Unlike util ExistsPath, this call does not perform follow link.
Expand Down
27 changes: 1 addition & 26 deletions pkg/os/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ func ValidatePathWindows(path string) error {
return nil
}

func Mkdir(path string) error {
if err := ValidatePathWindows(path); err != nil {
return err
}
return os.MkdirAll(path, 0755)
}

func Rmdir(path string, force bool) error {
if err := ValidatePathWindows(path); err != nil {
return err
Expand All @@ -135,36 +128,18 @@ func Rmdir(path string, force bool) error {
return os.Remove(path)
}

func LinkPath(sourcePath, targetPath string) error {
return CreateSymlink(sourcePath, targetPath)
}

func CreateSymlink(sourcePath, targetPath string) error {
if err := ValidatePathWindows(targetPath); err != nil {
return err
}
if err := ValidatePathWindows(sourcePath); err != nil {
return err
}
return os.Symlink(sourcePath, targetPath)
}

func IsMountPoint(path string) (bool, error) {
return IsSymlink(path)
}

func IsSymlink(path string) (bool, error) {
return isSymlink(path)
}

// IsSymlink - returns true if tgt is a mount point.
// A path is considered a mount point if:
// - directory exists and
// - it is a soft link and
// - the target path of the link exists.
// If tgt path does not exist, it returns an error
// if tgt path exists, but the source path tgt points to does not exist, it returns false without error.
func isSymlink(tgt string) (bool, error) {
func IsSymlink(tgt string) (bool, error) {
// This code is similar to k8s.io/kubernetes/pkg/util/mount except the pathExists usage.
stat, err := os.Lstat(tgt)
if err != nil {
Expand Down

0 comments on commit efcd49e

Please sign in to comment.