diff --git a/src/utils/conftree.cpp b/src/utils/conftree.cpp index b62a024d..7d364a7f 100755 --- a/src/utils/conftree.cpp +++ b/src/utils/conftree.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid [] = "@(#$Id: conftree.cpp,v 1.10 2007-08-04 07:22:43 dockes Exp $ (C) 2003 J.F.Dockes"; +static char rcsid [] = "@(#$Id: conftree.cpp,v 1.11 2007-09-27 11:02:13 dockes Exp $ (C) 2003 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -312,7 +312,11 @@ int ConfSimple::i_set(const std::string &nm, const std::string &value, } } } - m_order.insert(fin, ConfLine(ConfLine::CFL_VAR, nm)); + + // It may happen that the order entry already exists because erase doesnt + // update m_order (fix it ?) + if (find(start, fin, ConfLine(ConfLine::CFL_VAR, nm)) == fin) + m_order.insert(fin, ConfLine(ConfLine::CFL_VAR, nm)); return 1; } diff --git a/src/utils/conftree.h b/src/utils/conftree.h index 7496f446..d8bbd65d 100755 --- a/src/utils/conftree.h +++ b/src/utils/conftree.h @@ -341,6 +341,28 @@ public: { if (!m_ok) return 0; + + // Avoid adding unneeded entries: if the new value matches the + // one out of the deeper config, erase or dont add it from/to + // the topmost file + typename list::iterator it = m_confs.begin(); + it++; + while (it != m_confs.end()) { + string value; + if ((*it)->get(nm, value, sk)) { + // This file has value for nm/sk. If it is the same as the new + // one, no need for an entry in the topmost file. Else, stop + // looking and add the new entry + if (value == val) { + m_confs.front()->erase(nm, sk); + return true; + } else { + break; + } + } + it++; + } + return m_confs.front()->set(nm, val, sk); }