command line: added --delete-items

This complements --import/update/export/list-items. --remove was
already taken, for deleting a configuration.

Because the removal is done via the normal m_deleteItem operation, we
inherit the normal SyncML behavior (logging, no error return code for
non-existent items). It would have been nice to let the user choose
how to handle that situation (like --force in rm), but that can't be
done without SyncSource API changes.
This commit is contained in:
Patrick Ohly 2010-06-11 18:43:01 +02:00
parent 91e4b47931
commit 42e3588099
3 changed files with 37 additions and 1 deletions

View File

@ -53,6 +53,9 @@ Update item(s)
syncevolution --update <dir> <config> <source>
syncevolution [--delimiter <string>|none] --update <file>|- <config> <source> <luid> ...
Remove item(s):
syncevolution --delete-items <config> <source> <luid> ...
DESCRIPTION
===========
@ -230,6 +233,7 @@ refresh-from-client" in the next run. ::
syncevolution [--delimiter <string>|none] --import <dir>|<file>|- <config> <source>
syncevolution --update <dir> <config> <source>
syncevolution [--delimiter <string>|none] --update <file>|- <config> <source> <luid> ...
syncevolution --delete-items <config> <source> <luid> ...
Restore depends on the specific format of the automatic backups
created by SyncEvolution. Arbitrary access to item data is provided
@ -264,6 +268,14 @@ a directory, the name of each file is taken as its luid. When updating
from file or stdin, the number of luids given on the command line
must match with the number of items in the input.
--delete-items removes the specified items from the source. Most
backends print some progress information about this, but besides that,
no further output is produced. Trying to remove an item which does not
exist typically leads to an ERROR message, but is not reflected in a
non-zero result of the command line invocation itself because the
situation is not reported as an error by backends (removal of
non-existent items is not an error in SyncML).
OPTIONS
=======

View File

@ -224,6 +224,9 @@ bool Cmdline::parse(vector<string> &parsed)
}
m_delimiter = m_argv[opt];
parsed.push_back(m_delimiter);
} else if (boost::iequals(m_argv[opt], "--delete-items")) {
operations.push_back(m_argv[opt]);
m_deleteItems = m_accessItems = true;
} else if(boost::iequals(m_argv[opt], "--dry-run")) {
m_dryrun = true;
} else if(boost::iequals(m_argv[opt], "--migrate")) {
@ -758,6 +761,27 @@ bool Cmdline::run() {
}
m_out << luid << description << std::endl;
}
} else if (m_deleteItems) {
if (!ops.m_deleteItem) {
source->throwError("deleting items not supported");
}
err = ops.m_startDataRead("", "");
CHECK_ERROR("reading items");
if (ops.m_endDataRead) {
err = ops.m_endDataRead();
CHECK_ERROR("stop reading items");
}
if (ops.m_startDataWrite) {
err = ops.m_startDataWrite();
CHECK_ERROR("writing items");
}
BOOST_FOREACH(const string &luid, m_luids) {
sysync::ItemIDType id;
id.item = (char *)luid.c_str();
err = ops.m_deleteItem(&id);
CHECK_ERROR("deleting item");
}
// NO err = ops.m_endDataWrite(), see import/update below.
} else {
SyncSourceRaw *raw = dynamic_cast<SyncSourceRaw *>(source.get());
if (!raw) {

View File

@ -138,7 +138,7 @@ protected:
string m_itemPath;
string m_delimiter;
list<string> m_luids;
Bool m_printItems, m_update, m_import, m_export;
Bool m_printItems, m_update, m_import, m_export, m_deleteItems;
string m_server;
string m_template;