<commit_before>/**
 * @file
 *
 * @brief
 *
 * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
 */

#include <cp.hpp>

#include <cmdline.hpp>
#include <kdb.hpp>
#include <keysetio.hpp>
#include <rename.hpp>

#include <iostream>

using namespace std;
using namespace kdb;

CpCommand::CpCommand ()
{
}

namespace
{
void copySingleKey (Cmdline const & cl, Key const & rk, KeySet & tmpConf, KeySet & newConf)
{
	if (cl.force)
	{
		tmpConf.lookup (rk, KDB_O_POP);
	}
	else
	{
		Key key = tmpConf.lookup (rk);
		if (key != nullptr)
		{
			if (key.getString () != rk.getString ())
			{
				throw CommandAbortException (std::string ("Copy will not be done, because " + rk.getName () +
									  " already exists and has a different value"
									  ", use -f to force copy"),
							     11);
			}
		}
	}
	newConf.append (rk);
}
} // namespace<commit_msg>fix copy for binary keys<commit_after>/**
 * @file
 *
 * @brief
 *
 * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
 */

#include <cp.hpp>

#include <cmdline.hpp>
#include <kdb.hpp>
#include <keysetio.hpp>
#include <rename.hpp>

#include <iostream>

using namespace std;
using namespace kdb;

CpCommand::CpCommand ()
{
}

namespace
{
void copySingleKey (Cmdline const & cl, Key const & rk, KeySet & tmpConf, KeySet & newConf)
{
	if (cl.force)
	{
		tmpConf.lookup (rk, KDB_O_POP);
	}
	else
	{
		Key key = tmpConf.lookup (rk);
		if (key != nullptr)
		{
			if ((key.isString () && key.getString () != rk.getString ()) ||
			    (key.isBinary () && key.getBinary () != rk.getBinary ()))
			{
				throw CommandAbortException (std::string ("Copy will not be done, because " + rk.getName () +
									  " already exists and has a different value"
									  ", use -f to force copy"),
							     11);
			}
		}
	}
	newConf.append (rk);
}
} // namespace
{'fraction_non_alphanumeric': 0.15535035306898426, 'fraction_numerical': 0.0021727322107550242, 'mean_word_length': 2.9698275862068964, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '728627', 'n_tokens_mistral': 757, 'n_tokens_neox': 669, 'n_words': 175}