From 234346f18caf775625bbe88ef2eb7c3b17f3321b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 5 Jan 2017 18:16:52 +0100 Subject: Sinksh --- sinksh/syntax_modules/sink_list.cpp | 2 +- sinksh/syntax_modules/sink_sync.cpp | 54 ++++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) (limited to 'sinksh') diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index dd1498f..a609463 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp @@ -120,7 +120,7 @@ bool list(const QStringList &args_, State &state) } QStringList line; - line << o.resourceInstanceIdentifier(); + line << compressId(compact, o.resourceInstanceIdentifier()); line << compressId(compact, o.identifier()); for (const auto &prop: toPrint) { const auto value = o.getProperty(prop); diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp index d4a0e1c..f83f0d8 100644 --- a/sinksh/syntax_modules/sink_sync.cpp +++ b/sinksh/syntax_modules/sink_sync.cpp @@ -38,16 +38,62 @@ namespace SinkSync { -bool sync(const QStringList &args, State &state) +bool isId(const QByteArray &value) { + return value.startsWith("{"); +} + +bool sync(const QStringList &args_, State &state) +{ + auto args = args_; Sink::Query query; - for (const auto &res : args) { - query.resourceFilter(res.toLatin1()); + if (args.isEmpty()) { + state.printError(QObject::tr("Options: $type $resource/$folder/$subfolder")); + return false; + } + auto type = args.takeFirst().toLatin1(); + if (type != "*") { + query.setType(type); + } + if (!args.isEmpty()) { + auto resource = args.takeFirst().toLatin1(); + + if (resource.contains('/')) { + //The resource isn't an id but a path + auto list = resource.split('/'); + const auto resourceId = list.takeFirst(); + query.resourceFilter(resourceId); + if (type == Sink::ApplicationDomain::getTypeName() && !list.isEmpty()) { + auto value = list.takeFirst(); + if (isId(value)) { + query.filter(value); + } else { + Sink::Query folderQuery; + folderQuery.resourceFilter(resourceId); + folderQuery.filter(value); + folderQuery.filter(QVariant()); + qWarning() << "Looking for folder: " << value << " in " << resourceId; + auto folders = Sink::Store::read(folderQuery); + if (folders.size() == 1) { + query.filter(folders.first()); + qWarning() << "Synchronizing folder: " << folders.first().identifier(); + } else { + qWarning() << "Folder name did not match uniquely: " << folders.size(); + for (const auto &f : folders) { + qWarning() << f.getName(); + } + state.printError(QObject::tr("Folder name did not match uniquely.")); + } + } + } + } else { + query.resourceFilter(resource); + } } QTimer::singleShot(0, [query, state]() { Sink::Store::synchronize(query) - .then(Sink::ResourceControl::flushReplayQueue(query.getResourceFilter().ids)) + .then(Sink::ResourceControl::flushMessageQueue(query.getResourceFilter().ids)) .syncThen([state](const KAsync::Error &error) { if (error) { state.printLine("Synchronization failed!"); -- cgit v1.2.3