Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: windows functions #2710

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/mounter/safe_mounter_host_process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func NewWinMounter(listDisksUsingWinCIM bool) *winMounter {
}

// 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))
func (mounter *winMounter) Mount(source, target, _ string, _ []string) error {
return os.Symlink(normalizeWindowsPath(source), normalizeWindowsPath(target))
}

// Rmdir - delete the given directory
Expand Down Expand Up @@ -111,7 +111,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 @@ -104,13 +104,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 @@ -122,36 +115,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
11 changes: 0 additions & 11 deletions pkg/os/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ import (
"sigs.k8s.io/azuredisk-csi-driver/pkg/azureutils"
)

var (
// VolumeRegexp matches a Windows Volume
// example: Volume{452e318a-5cde-421e-9831-b9853c521012}
//
// The field UniqueId has an additional prefix which is NOT included in the regex
// however the regex can match UniqueId too
// PS C:\disks> (Get-Disk -Number 1 | Get-Partition | Get-Volume).UniqueId
// \\?\Volume{452e318a-5cde-421e-9831-b9853c521012}\
VolumeRegexp = regexp.MustCompile(`Volume\{[\w-]*\}`)
)

func getVolumeSize(volumeID string) (int64, error) {
cmd := "(Get-Volume -UniqueId \"$Env:volumeID\" | Get-partition).Size"
out, err := azureutils.RunPowershellCmd(cmd, fmt.Sprintf("volumeID=%s", volumeID))
Expand Down
Loading