Skip to content

Commit

Permalink
Merge pull request #573 from Tarsnap/cmdlinetask-relative-executables
Browse files Browse the repository at this point in the history
Relative executable paths in CmdlineTask
  • Loading branch information
gperciva authored Dec 4, 2023
2 parents e759f87 + 664a96f commit 1d70188
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/cmdlinetask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ WARNINGS_ENABLE

#include "ConsoleLog.h"

#include "dir-utils.h"

#include <signal.h>

#define DEFAULT_TIMEOUT_MS 5000
Expand Down Expand Up @@ -80,7 +82,9 @@ void CmdlineTask::run()

// Make sure that the command exists and is executable, because QProcess
// doesn't clean up its memory if it fails due to "command not found".
if(QStandardPaths::findExecutable(_command).isEmpty())
// We can't use QStandardPaths::findExecutable(), because that can't
// handle relative paths.
if(!validate_executable(_command).isEmpty())
{
LOG << QString("Command '%1' not found\n").arg(_command);
emit finished(_data, EXIT_CMD_NOT_FOUND, "", "");
Expand Down
2 changes: 1 addition & 1 deletion src/dir-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ QString validate_readable_file(const QString &filename)
return ("");
}

static QString validate_executable(const QString &executable)
QString validate_executable(const QString &executable)
{
if(executable.isEmpty())
return (
Expand Down
4 changes: 4 additions & 0 deletions src/dir-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ struct DirMessage
struct DirMessage findTarsnapClientInPath(const QString &path,
bool keygenToo = false);

// Return the reason why filename is not executable, or empty string for
// success.
QString validate_executable(const QString &executable);

// Search for valid tarsnap keys in the supplied path
QFileInfoList findKeysInPath(const QString &path);

Expand Down
4 changes: 2 additions & 2 deletions src/tasks/tasks-misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ CmdlineTask *sleepSecondsTask(int seconds)
QStringList args;

/* Specific arguments. */
task->setCommand("sleep");
args << QString::number(seconds);
task->setCommand("/bin/sh");
args << "sleep" << QString::number(seconds);

/* Generic setup. */
task->setArguments(args);
Expand Down
2 changes: 2 additions & 0 deletions tests/task/test-task.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ HEADERS += \
../../lib/core/TSettings.h \
../../src/basetask.h \
../../src/cmdlinetask.h \
../../src/dir-utils.h \
../../src/tasks/tasks-utils.h \
../qtest-platform.h

Expand All @@ -16,6 +17,7 @@ SOURCES += test-task.cpp \
../../lib/core/TSettings.cpp \
../../src/basetask.cpp \
../../src/cmdlinetask.cpp \
../../src/dir-utils.cpp \
../../src/tasks/tasks-utils.cpp

include(../tests-include.pri)

0 comments on commit 1d70188

Please sign in to comment.