Skip to content

Commit e515a4b

Browse files
committed
The parentheses are needed for the shell command to be executed properly.
If the shell command looks like "condition1 && command1 || condition2 && command2 || command3" then condition2 will never be checked if condition1 is true and command1 exists normally. In order for this code to run expectedly, it should look like "(condition1 && command1) || (condition2 && command2) || command3" instead. Specifically, with the code like "[ ! -d /Users ]&& sudo mkdir /Users; sudo mount --bind /mnt/hgfs/Users /Users || [ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/Users /Users || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/Users /Users" if both "[ ! -d /Users ]" and "sudo mkdir /Users; sudo mount --bind /mnt/hgfs/Users /Users" are true, then the existence of a file /usr/local/bin/vmhgfs-fuse will never be examined and always be executed even if the file doesn't exist. Consequently, it always fails. Signed-off-by: Motonori Shindo <motonori@shin.do>
1 parent 7890e8d commit e515a4b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/vmwarefusion/fusion_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func (d *Driver) Create() error {
403403
if err != nil {
404404
return err
405405
}
406-
command := "[ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; sudo mount --bind /mnt/hgfs/" + shareDir + " " + shareDir + " || [ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + " || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/" + shareName + " " + shareDir
406+
command := "([ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; sudo mount --bind /mnt/hgfs/" + shareDir + " " + shareDir + ") || ([ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + ") || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/" + shareName + " " + shareDir
407407
_, _, err = vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", command)
408408
if err != nil {
409409
return err
@@ -436,7 +436,7 @@ func (d *Driver) Start() error {
436436
return err
437437
} else if !os.IsNotExist(err) {
438438
// create mountpoint and mount shared folder
439-
command := "[ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; sudo mount --bind /mnt/hgfs/" + shareDir + " " + shareDir + " || [ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + " || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/" + shareName + " " + shareDir
439+
command := "([ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; sudo mount --bind /mnt/hgfs/" + shareDir + " " + shareDir + ") || ([ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + ") || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/" + shareName + " " + shareDir
440440
vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", command)
441441
}
442442
}

0 commit comments

Comments
 (0)