Skip to content

Commit

Permalink
further improved rclone options parsing - #79
Browse files Browse the repository at this point in the history
  • Loading branch information
kapitainsky committed Feb 22, 2020
1 parent 984c656 commit 3f11df2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/job_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ QStringList JobOptions::getOptions() const {
}

if (!extra.isEmpty()) {
QRegExp separator("--");
for (auto arg : extra.split(separator)) {
if (!arg.isEmpty()) {
list << "--"+arg;
// split on spaces but not if inside quotes e.g. --option-1 --option-2="arg1 arg2" --option-3 arg3
// should generate "--option-1" "--option-2=\"arg1 arg2\"" "--option-3" "arg3"
for (QString arg : extra.split(QRegExp(" (?=[^\"]*(\"[^\"]*\"[^\"]*)*$)"))) {
if (!arg.isEmpty()) {
list << arg;
}
}
}
}

if (DriveSharedWithMe) {
list << "--drive-shared-with-me";
Expand Down
10 changes: 9 additions & 1 deletion src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,17 @@ void MainWindow::addMount(const QString &remote, const QString &folder) {
// args << "writes";

args.append(GetRcloneConf());

if (!opt.isEmpty()) {
args.append(opt.split(' '));
// split on spaces but not if inside quotes e.g. --option-1 --option-2="arg1 arg2" --option-3 arg3
// should generate "--option-1" "--option-2=\"arg1 arg2\"" "--option-3" "arg3"
for (QString arg : opt.split(QRegExp(" (?=[^\"]*(\"[^\"]*\"[^\"]*)*$)"))) {
if (!arg.isEmpty()) {
args << arg;
}
}
}

args << remote << folder;

UseRclonePassword(mount);
Expand Down
9 changes: 6 additions & 3 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,17 @@ QStringList GetDefaultRcloneOptionsList() {
QString defaultRcloneOptions =
settings->value("Settings/defaultRcloneOptions").toString();
QStringList defaultRcloneOptionsList;

if (!defaultRcloneOptions.isEmpty()) {
QRegExp separator("--");
for (auto arg : defaultRcloneOptions.split(separator)) {
// split on spaces but not if inside quotes e.g. --option-1 --option-2="arg1 arg2" --option-3 arg3
// should generate "--option-1" "--option-2=\"arg1 arg2\"" "--option-3" "arg3"
for (QString arg : defaultRcloneOptions.split(QRegExp(" (?=[^\"]*(\"[^\"]*\"[^\"]*)*$)"))) {
if (!arg.isEmpty()) {
defaultRcloneOptionsList << "--"+arg;
defaultRcloneOptionsList << arg;
}
}
}

return defaultRcloneOptionsList;
}

Expand Down

0 comments on commit 3f11df2

Please sign in to comment.