gerardog/gsudo

Issue: Having spaces in the parameters of kopia.exe will cause an error

LakeishaKowalczyk opened this issue · 7 comments

Issue Description

failed with sudo

❯ sudo d:\Programs\BackupSync\KopiaUI_Portable\resources\server\kopia.exe --config-file=D:\Programs\BackupSync\KopiaUI_Portable\repositories\repository.config --log-dir=D:\Programs\BackupSync\KopiaUI_Portable\repositories\logs\repository snapshot create "D:\My Documents\Downloads"

Snapshotting xx@desktop-jjj4xx7:D:\My ...
Snapshotting xx@desktop-jjj4xx7:C:\Users\Fz\Documents\Downloads ...
ERROR encountered 2 errors:
unable to get local filesystem entry: resolveSymlink: stat: CreateFile D:\My: The system cannot find the file specified.
unable to get local filesystem entry: resolveSymlink: stat: CreateFile C:\Users\Fz\Documents\Downloads: The system cannot find the path specified.

Succeeded without sudo

❯ sudo
❯ d:\Programs\BackupSync\KopiaUI_Portable\resources\server\kopia.exe --config-file=D:\Programs\BackupSync\KopiaUI_Portable\repositories\repository.config --log-dir=D:\Programs\BackupSync\KopiaUI_Portable\repositories\logs\repository snapshot create "D:\My Documents\Downloads"

Snapshotting xx@desktop-jjj4xx7:D:\My Documents\Downloads ...
 * 0 hashing, 1 hashed (0 B), 3 cached (6.9 GB), uploaded 199 B, estimated 6.9 GB (100.0%) 0s left
Created snapshot with root k40689d35ba6aa36a820b0fe8d28d17f5 and ID a55f7f9bc0e95aaf7f902fca4ad4352b in 4s

Steps to Reproduce

Screenshots

Context:

  • Windows version:
    Win11 21H2
  • gsudo version:
    gsudo v2.4.0 (Branch.tags-v2.4.0.Sha.5cb99680b71a0116c002c5b42d9d6ac249786914)

Which shell are you using? CMD, PowerShell, or another one?

for Pwsh the correct syntax is sudo { command to elevate }

Thanks, I'm using PowerShell 7, {} did this magic

If the file path does not contain any spaces, it can be executed directly, and sudo notepad D:\dir with space\test.txt works fine.
Could gsudo automatically add {} for all programs? This seems to be more intuitive

Unfortunatelly, no. The quotes pass thru several stages, from powershell to gsudo call, and from gsudo call to pwsh call again. Sometimes I need to add a wrapper cmd to workaround other problems... and some loose of fidelity usually ocurrs, like single quotes changed to double quotes... I may review your specific case later, but the simple way to avoid every problem is using brackets { }, which makes powershell to encode the command before sending it to gsudo.

btw if you used single quotes, it would have worked, because:

image

powershell has some quirks, and needs to stay backward compatible because that's Microsoft way.

try this edit your profile file notepad $profile, add this line: import gsudoModule
then restart your powershells
run your command, it fails...
write 'gsudo ' (type a space after gsudo) then press tab key....
It will autocomplete with gsudo { you last command }

Thanks a lot
So { } is prepared for powershell, not for gsudo to use. Gsudo cannot directly obtain the user’s actual input, but can only obtain the processed code passed by powershell. Is my understanding correct?
In addition, the results of single and double quotes are the same

Yes, { } is transformed by powershell, before calling gsudo.

Nonetheless, I am seeing some strange behaviour on gsudo and I may check if I can fix it on another day, and hopefully improve how it works without the brackets {}. Nonetheless do not expect that gsudo without {} will always work, because there are always edge cases.