Don't crash if target-keys have same values as source-keys
@@ -30,13 +30,25 @@ void copySingleKey (Cmdline const & cl, Key const & rk, KeySet & tmpConf, KeySet
{
tmpConf.lookup (rk, KDB_O_POP);
}
- else if (tmpConf.lookup (rk))
+ else
+ {
+ Key key = tmpConf.lookup (rk);
+ if (key != nullptr)
{
- throw CommandAbortException (
- std::string ("Copy will not be done, because " + rk.getName () + " already exists, use -f to force copy"), 11);
+ 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);
+ }
}
+ else
+ {
newConf.append (rk);
}
+ }
+}
} // namespace
int CpCommand::execute (Cmdline const & cl)
