|
1 | 1 | package filesystem
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "errors" |
4 | 5 | "fmt"
|
5 | 6 | "os"
|
6 | 7 | "path/filepath"
|
7 |
| - "strings" |
8 | 8 |
|
9 |
| - "github.com/kubernetes-csi/csi-proxy/pkg/utils" |
| 9 | + "golang.org/x/sys/windows" |
10 | 10 | )
|
11 | 11 |
|
12 | 12 | // Implements the Filesystem OS API calls. All code here should be very simple
|
@@ -50,14 +50,22 @@ func (filesystemAPI) PathExists(path string) (bool, error) {
|
50 | 50 | }
|
51 | 51 |
|
52 | 52 | func pathValid(path string) (bool, error) {
|
53 |
| - cmd := `Test-Path $Env:remotepath` |
54 |
| - cmdEnv := fmt.Sprintf("remotepath=%s", path) |
55 |
| - output, err := utils.RunPowershellCmd(cmd, cmdEnv) |
| 53 | + pathString, err := windows.UTF16PtrFromString(path) |
56 | 54 | if err != nil {
|
57 |
| - return false, fmt.Errorf("returned output: %s, error: %v", string(output), err) |
| 55 | + return false, fmt.Errorf("invalid path: %w", err) |
58 | 56 | }
|
59 | 57 |
|
60 |
| - return strings.HasPrefix(strings.ToLower(string(output)), "true"), nil |
| 58 | + attrs, err := windows.GetFileAttributes(pathString) |
| 59 | + if err != nil { |
| 60 | + if errors.Is(err, windows.ERROR_PATH_NOT_FOUND) || errors.Is(err, windows.ERROR_FILE_NOT_FOUND) || errors.Is(err, windows.ERROR_INVALID_NAME) { |
| 61 | + return false, nil |
| 62 | + } |
| 63 | + |
| 64 | + // GetFileAttribute returns user or password incorrect for a disconnected SMB connection after the password is changed |
| 65 | + return false, fmt.Errorf("failed to get path %s attribute: %w", path, err) |
| 66 | + } |
| 67 | + |
| 68 | + return attrs != windows.INVALID_FILE_ATTRIBUTES, nil |
61 | 69 | }
|
62 | 70 |
|
63 | 71 | // PathValid determines whether all elements of a path exist
|
|
0 commit comments