Skip to content

Commit 49a5c69

Browse files
Fix case sensitive unmount (#520)
* Fix case insensitive unmount on Windows * Test for valid drive path * Add test for valid windows drive letter * Fix failing tests for Windows * Fix tests and code * Add fix to allow unmounting existing mounts that were case sensitive * Cleanup code
1 parent 8870c7c commit 49a5c69

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

internal/winservice/service_windows.go

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"encoding/binary"
3232
"errors"
3333
"fmt"
34+
"strings"
3435

3536
"github.com/Seagate/cloudfuse/common"
3637
"github.com/Seagate/cloudfuse/common/log"
@@ -51,15 +52,15 @@ const (
5152

5253
// StartMount starts the mount if the name exists in the WinFsp Windows registry.
5354
func StartMount(mountPath string, configFile string, passphrase *memguard.Enclave) error {
55+
instanceName := strings.ToLower(mountPath)
56+
5457
// get the current user uid and gid to set file permissions
5558
userId, groupId, err := common.GetCurrentUser()
5659
if err != nil {
57-
log.Err("StartMount : GetCurrentUser() failed with error: %v", err)
60+
log.Err("startMountHelper : GetCurrentUser() failed with error: %v", err)
5861
return err
5962
}
6063

61-
instanceName := mountPath
62-
6364
if passphrase != nil {
6465
buff, err := passphrase.Open()
6566
if err != nil || buff == nil {
@@ -72,15 +73,12 @@ func StartMount(mountPath string, configFile string, passphrase *memguard.Enclav
7273
} else {
7374
_, err = winFspCommand(writeCommandToUtf16(startCmd, SvcName, instanceName, mountPath, configFile, fmt.Sprint(userId), fmt.Sprint(groupId), ""))
7475
}
75-
if err != nil {
76-
return err
77-
}
78-
return nil
76+
return err
7977
}
8078

8179
// StopMount stops the mount if the name exists in the WinFsp Windows registry.
8280
func StopMount(mountPath string) error {
83-
instanceName := mountPath
81+
instanceName := strings.ToLower(mountPath)
8482

8583
buf := writeCommandToUtf16(stopCmd, SvcName, instanceName, mountPath)
8684
_, err := winFspCommand(buf)
@@ -92,21 +90,15 @@ func StopMount(mountPath string) error {
9290

9391
// IsMounted determines if the given path is mounted.
9492
func IsMounted(mountPath string) (bool, error) {
95-
buf := writeCommandToUtf16(listCmd)
96-
list, err := winFspCommand(buf)
93+
instanceName := strings.ToLower(mountPath)
94+
list, err := getMountList()
9795
if err != nil {
9896
return false, err
9997
}
10098

101-
// Everything in the list is a name of a service using WinFsp, like cloudfuse and then
102-
// the name of the mount which is the mount path
103-
if len(list)%2 != 0 {
104-
return false, errors.New("unable to get list from Winfsp because received odd number of elements")
105-
}
106-
10799
for i := 0; i < len(list); i += 2 {
108100
// Check if the mountpath is associated with our service
109-
if list[i] == SvcName && list[i+1] == mountPath {
101+
if list[i] == SvcName && list[i+1] == instanceName {
110102
return true, nil
111103
}
112104
}
@@ -151,6 +143,23 @@ func StopMounts(useSystem bool) error {
151143
return nil
152144
}
153145

146+
func getMountList() ([]string, error) {
147+
var emptyList []string
148+
buf := writeCommandToUtf16(listCmd)
149+
list, err := winFspCommand(buf)
150+
if err != nil {
151+
return emptyList, err
152+
}
153+
154+
// Everything in the list is a name of a service using WinFsp, like cloudfuse and then
155+
// the name of the mount which is the mount path
156+
if len(list)%2 != 0 {
157+
return emptyList, errors.New("unable to get list from Winfsp because received odd number of elements")
158+
}
159+
160+
return list, nil
161+
}
162+
154163
// writeCommandToUtf16 writes a given cmd and arguments as a byte array in UTF16.
155164
func writeCommandToUtf16(cmd uint16, args ...string) []byte {
156165
var buf bytes.Buffer

0 commit comments

Comments
 (0)