Skip to content

Commit

Permalink
Allow to specify a server url diferent than the sync url
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Nov 8, 2022
1 parent 772a8e4 commit cbb0b37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/10239
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Change: owncloudcmd OCIS support

When using ocis and spaces with the cmd client the additional parameter `--server` is required.
`--server` spcifies the url to the server, while the positional parameter 'server_url' specifies the webdav url.

https://github.com/owncloud/client/pull/10239
26 changes: 19 additions & 7 deletions src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct CmdOptions
{
QString source_dir;
QUrl target_url;
QUrl server_url;

QString remoteFolder;
QString config_directory;
QString user;
Expand All @@ -74,7 +76,6 @@ struct SyncCTX
{
}
CmdOptions options;
QUrl credentialFreeUrl;
AccountPtr account;
QString user;
};
Expand Down Expand Up @@ -133,7 +134,7 @@ void sync(const SyncCTX &ctx)
opt.fillFromEnvironmentVariables();
opt.verifyChunkSizes();
auto engine = new SyncEngine(
ctx.account, ctx.account->davUrl(), ctx.options.source_dir, ctx.options.remoteFolder, db);
ctx.account, ctx.options.target_url, ctx.options.source_dir, ctx.options.remoteFolder, db);
engine->setSyncOptions(opt);
engine->setParent(db);

Expand Down Expand Up @@ -320,6 +321,7 @@ CmdOptions parseOptions(const QStringList &app_args)
auto excludeOption = addOption({ { QStringLiteral("exclude") }, QStringLiteral("Path to an exclude list [file]"), QStringLiteral("file") });
auto unsyncedfoldersOption = addOption({ { QStringLiteral("unsyncedfolders") }, QStringLiteral("File containing the list of unsynced remote folders (selective sync)"), QStringLiteral("file") });

auto serverOption = addOption({ { QStringLiteral("server") }, QStringLiteral("Use [url] as the location of the server. OCIS only (server location and spaces url can differ)"), QStringLiteral("url") });
auto userOption = addOption({ { QStringLiteral("u"), QStringLiteral("user") }, QStringLiteral("Use [name] as the login name"), QStringLiteral("name") });
auto passwordOption = addOption({ { QStringLiteral("p"), QStringLiteral("password") }, QStringLiteral("Use [pass] as password"), QStringLiteral("password") });
auto useNetrcOption = addOption({ { QStringLiteral("n") }, QStringLiteral("Use netrc (5) for login") });
Expand Down Expand Up @@ -379,6 +381,9 @@ CmdOptions parseOptions(const QStringList &app_args)
if (parser.isSet(nonInterActiveOption)) {
options.interactive = false;
}
if (parser.isSet(serverOption)) {
options.server_url = QUrl::fromUserInput(parser.value(serverOption));
}
if (parser.isSet(userOption)) {
options.user = parser.value(userOption);
}
Expand Down Expand Up @@ -433,22 +438,29 @@ int main(int argc, char **argv)

setupCredentials(ctx);

if (!ctx.options.target_url.path().contains(ctx.account->davPath())) {
ctx.options.target_url = OCC::Utility::concatUrlPath(ctx.options.target_url, ctx.account->davPath());
if (ctx.options.server_url.isEmpty()) {
ctx.options.server_url = ctx.options.target_url;
// guess dav path
if (!ctx.options.target_url.path().contains(ctx.account->davPath())) {
ctx.options.target_url = OCC::Utility::concatUrlPath(ctx.options.target_url, ctx.account->davPath());
}
}

// don't leak credentials more than needed
ctx.options.server_url = ctx.options.server_url.adjusted(QUrl::RemoveUserInfo);
ctx.options.target_url = ctx.options.target_url.adjusted(QUrl::RemoveUserInfo);

const QUrl baseUrl = [&ctx] {
auto tmp = ctx.options.target_url;
auto tmp = ctx.options.server_url;
// Find the folder and the original owncloud url
QStringList splitted = tmp.path().split(ctx.account->davPath());
tmp.setPath(splitted.value(0));
tmp.setScheme(tmp.scheme().replace(QLatin1String("owncloud"), QLatin1String("http")));
return tmp;
}();
ctx.credentialFreeUrl = baseUrl.adjusted(QUrl::RemoveUserInfo);


ctx.account->setUrl(ctx.credentialFreeUrl);
ctx.account->setUrl(baseUrl);

auto *checkServerJob = CheckServerJobFactory(ctx.account->accessManager()).startJob(ctx.account->url());

Expand Down

0 comments on commit cbb0b37

Please sign in to comment.