[CommandLauncherJob] Add constructor taking an executable and argument list
ClosedPublic

Authored by broulik on Apr 2 2020, 1:17 PM.

Details

Summary

More convenient than having to construct a proper escaped commandline.

Test Plan
  • Ported the runners in D28512 to use it, had something with a space properly escaped

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik created this revision.Apr 2 2020, 1:17 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptApr 2 2020, 1:17 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
broulik requested review of this revision.Apr 2 2020, 1:17 PM
dfaure accepted this revision.Apr 2 2020, 1:33 PM

KProcessRunner::KProcessRunner(QString cmd) calls KProcess::setShellCommand(cmd) which ... has two modes. Either KShell::splitArgs()[0] finds an executable that exists (checking that there is no "&&" or "||" or ";" in the command) in which case it uses the splitted args, and no /bin/sh is involved, *or* it passes the whole command as is to "sh -c", as a single argument. That first optimization aside, it is logical for setShellCommand to take a single string. So It's logical to me that KProcessRunner takes a single string, and that you join the stringlist in CommandLauncherJob.

This revision is now accepted and ready to land.Apr 2 2020, 1:33 PM

Ok, makes sense. Just realized: do I need to quoteArgs the executable?

dfaure added a comment.Apr 2 2020, 4:16 PM

Good question. I haven't seen that done in most callers, but indeed, what if it's in a path with a space, like often happens on Windows?
It sounds like the answer is yes, it should be quoted.
The real answer is to write a CommandLauncherJob unittest for such a case, of course :-)

broulik updated this revision to Diff 79189.Apr 3 2020, 7:40 AM
broulik edited the test plan for this revision. (Show Details)
  • Quote executable in commandline
  • Add unittest

Not sure how I would test running a command with a space in it.. putting a shell script in running it through QFINDTESTDATA? Not sure how to make that sort of stuff work on Windows

You could create a subdir of a QTemporaryDir with a fixed name like "abc def", copy cp or copy.exe in there, and then run that with an absolute path?

broulik planned changes to this revision.Apr 4 2020, 7:43 AM

Good idea

broulik updated this revision to Diff 79267.Apr 4 2020, 9:17 AM
  • Add test for binary in path with space
This revision is now accepted and ready to land.Apr 4 2020, 9:17 AM
broulik requested review of this revision.Apr 4 2020, 9:17 AM
dfaure accepted this revision.Apr 4 2020, 9:22 AM

Awesome.

This revision is now accepted and ready to land.Apr 4 2020, 9:22 AM
This revision was automatically updated to reflect the committed changes.