예제 #1
0
void test_basic()
{
	cout << "testing metainfo" << endl;
	Key test;

	succeed_if (test.hasMeta("mode") == false, "has meta?");
	succeed_if (test.getMeta<mode_t>("mode") == 0, "not properly default constructed");

	test.setMeta<mode_t>("mode", 0775);
	succeed_if (test.hasMeta("mode") == true, "has not meta even though set?");

	succeed_if (test.getMeta<mode_t>("mode") == 0775, "not correct default mode for dir");

	test.setMeta<int>("myint", 333);
	succeed_if (test.getMeta<int>("myint") == 333, "could not set other meta");

	test.setMeta<double>("mydouble", 333.3);
	succeed_if (test.hasMeta("mydouble"), "no meta data even though it was just set");
	succeed_if (test.getMeta<double>("mydouble") >= 333.2, "could not set other meta");
	succeed_if (test.getMeta<double>("mydouble") <= 333.4, "could not set other meta");

	test.delMeta("mydouble");
	succeed_if (!test.hasMeta("mydouble"), "meta data there even though it was just deleted");

	test.setMeta<std::string>("mystr", "str");
	succeed_if (test.getMeta<std::string>("mystr") == "str", "could not set other meta");

	const ckdb::Key *cmeta = test.getMeta<const ckdb::Key*>("mystr");
	succeed_if (!strcmp(static_cast<const char*>(ckdb::keyValue(cmeta)), "str"), "could not set other meta");

	const ckdb::Key *nmeta = test.getMeta<const ckdb::Key*>("not available");
	succeed_if (nmeta == 0, "not available meta data did not give a null pointer");

	const Key meta = test.getMeta<const Key>("mystr");
	succeed_if (meta, "null key");
	succeed_if (meta.getString() == "str", "could not get other meta");

	const Key xmeta = test.getMeta<const Key>("not available");
	succeed_if (!xmeta, "not a null key");

	const char * str = test.getMeta<const char*>("mystr");
	succeed_if (!strcmp(str, "str"), "could not get meta as c-string");

	const char * nstr = test.getMeta<const char*>("not available");
	succeed_if (nstr == 0, "did not get null pointer on not available meta data");

	succeed_if (test.getMeta<int>("not available") == 0, "not default constructed");
	succeed_if (test.getMeta<std::string>("not available") == "", "not default constructed");

	test.setMeta<std::string>("wrong", "not an int");

	try {
		succeed_if (test.hasMeta("wrong") == true, "meta is here");
		test.getMeta<int>("wrong");
		succeed_if (0, "exception did not raise");
	} catch (KeyTypeConversion const& e)
	{
		succeed_if (1, "no such meta data");
	}
}
예제 #2
0
void MergeResult::addConflict(Key& key, ConflictOperation ourOperation,
		ConflictOperation theirOperation)
{
	key.rewindMeta();
	while (Key currentMeta = key.nextMeta())
	{
		key.delMeta(currentMeta.getName());
	}

	if (key.isString())
	{
		key.setString("");
	}
	else
	{
		key.setBinary(nullptr, 0);
	}

	removeMergeKey (key);
	key.setMeta ("conflict/operation/our",
			MergeConflictOperation::getFromTag (ourOperation));
	key.setMeta ("conflict/operation/their",
			MergeConflictOperation::getFromTag (theirOperation));
	conflictSet.append (key);
}
예제 #3
0
int MetaRemoveCommand::execute (Cmdline const & cl)
{
	if (cl.arguments.size () != 2)
	{
		throw invalid_argument ("Need 2 arguments");
	}
	Key parentKey = cl.createKey (0);
	string metaname = cl.arguments[1];

	KeySet conf;
	kdb.get (conf, parentKey);
	printWarnings (cerr, parentKey);

	Key k = conf.lookup (parentKey);

	if (!k)
	{
		cerr << "Key not found" << endl;
		return 1;
	}

	k.delMeta (metaname);

	kdb.set (conf, parentKey);

	return 0;
}
예제 #4
0
int MetaSetCommand::execute (Cmdline const & cl)
{
	if (cl.arguments.size () < 2 || cl.arguments.size () > 3)
	{
		throw invalid_argument ("Need 2 or 3 arguments");
	}
	string metaname = cl.arguments[1];

	Key parentKey = cl.createKey (0);
	string keyname = parentKey.getName ();
	if (keyname[0] == '/')
	{
		// fix name for lookup
		keyname = "spec" + keyname;
		if (!cl.quiet) std::cout << "Using keyname " << keyname << std::endl;

		// fix k for kdb.set later
		parentKey.setName (keyname);
	}

	KeySet conf;
	kdb.get (conf, parentKey);
	Key k = conf.lookup (parentKey);

	if (!k)
	{
		k = Key (keyname, KEY_END);
		// k.setBinary(0, 0); // conceptually maybe better, but would have confusing "binary" metadata
		conf.append (k);
		if (cl.verbose) cout << "Creating key " << keyname << endl;
	}
	if (!k.isValid ())
	{
		cerr << "Could not create key " << keyname << endl;
		return 1;
	}

	if (cl.arguments.size () == 2)
	{
		if (!cl.quiet) cout << "Only two arguments, thus deleting metaname " << metaname << endl;
		k.delMeta (metaname);
	}
	else
	{
		std::string metavalue = cl.arguments[2];
		if (metaname == "atime" || metaname == "mtime" || metaname == "ctime")
		{
			stringstream str (metavalue);
			time_t t;
			str >> t;
			if (!str.good ()) throw "conversion failure";
			k.setMeta<time_t> (metaname, t);
		}
		else
		{
예제 #5
0
void MergeResult::resolveConflict(Key& key)
{
	key.rewindMeta();
	Key currentMeta;
	while ((currentMeta = key.nextMeta()))
	{
		// TODO: this is just a workaround because keys with a prefix other than
		// user/ or system/ cannot be created and therefore isBelow cannot be used
		if (currentMeta.getName().find("conflict/") == 0)
		{
			key.delMeta(currentMeta.getName());
		}
	}

	conflictSet.lookup(key, KDB_O_POP);
	resolvedKeys++;
}