aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-11 09:53:36 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-11 09:53:36 +0100
commitf43ee8ee592a57d79f5f9eff75ac58fe7b223199 (patch)
treebde7744ae651ae77ed2e33477f9a64ca5186f7f4
parent599c00bf450d19a4050d4c263817729bdb4eecac (diff)
downloadpaludis-f43ee8ee592a57d79f5f9eff75ac58fe7b223199.tar.gz
paludis-f43ee8ee592a57d79f5f9eff75ac58fe7b223199.tar.xz
Return whether we change a set
-rw-r--r--paludis/set_file.cc29
-rw-r--r--paludis/set_file.hh4
2 files changed, 23 insertions, 10 deletions
diff --git a/paludis/set_file.cc b/paludis/set_file.cc
index a8c7442..7e40caf 100644
--- a/paludis/set_file.cc
+++ b/paludis/set_file.cc
@@ -58,7 +58,7 @@ namespace
virtual ~SetFileHandler();
virtual std::tr1::shared_ptr<SetSpecTree> contents() const = 0;
- virtual void add(const std::string &) = 0;
+ virtual bool add(const std::string &) = 0;
virtual bool remove(const std::string &) = 0;
virtual void rewrite() const = 0;
};
@@ -79,7 +79,7 @@ namespace
PaludisConfHandler(const SetFileParams &);
virtual std::tr1::shared_ptr<SetSpecTree> contents() const;
- virtual void add(const std::string &);
+ virtual bool add(const std::string &);
virtual bool remove(const std::string &);
virtual void rewrite() const;
};
@@ -95,7 +95,7 @@ namespace
PaludisBashHandler(const SetFileParams &);
virtual std::tr1::shared_ptr<SetSpecTree> contents() const;
- virtual void add(const std::string &) PALUDIS_ATTRIBUTE((noreturn));
+ virtual bool add(const std::string &) PALUDIS_ATTRIBUTE((noreturn));
virtual bool remove(const std::string &) PALUDIS_ATTRIBUTE((noreturn));
virtual void rewrite() const PALUDIS_ATTRIBUTE((noreturn));
};
@@ -116,7 +116,7 @@ namespace
SimpleHandler(const SetFileParams &);
virtual std::tr1::shared_ptr<SetSpecTree> contents() const;
- virtual void add(const std::string &);
+ virtual bool add(const std::string &);
virtual bool remove(const std::string &);
virtual void rewrite() const;
};
@@ -372,15 +372,21 @@ SimpleHandler::contents() const
return _contents;
}
-void
+bool
SimpleHandler::add(const std::string & p)
{
Lock l(_mutex);
+ bool result(false);
if (_lines.end() == std::find(_lines.begin(), _lines.end(), p))
+ {
+ result = true;
_lines.push_back(p);
+ }
_contents.reset();
+
+ return result;
}
bool
@@ -462,15 +468,20 @@ PaludisConfHandler::contents() const
return _contents;
}
-void
+bool
PaludisConfHandler::add(const std::string & p)
{
Lock l(_mutex);
+ bool result(false);
if (_lines.end() == std::find_if(_lines.begin(), _lines.end(), TokenOneIs(p)))
+ {
+ result = true;
_lines.push_back("* " + p);
+ }
_contents.reset();
+ return result;
}
bool
@@ -555,7 +566,7 @@ PaludisBashHandler::contents() const
return _contents;
}
-void
+bool
PaludisBashHandler::add(const std::string & p)
{
throw SetFileError(_p.file_name(), "Cannot add entry '" + p + "' to bash script '" + stringify(_p.file_name()) + "'");
@@ -610,10 +621,10 @@ SetFile::rewrite() const
_imp->handler->rewrite();
}
-void
+bool
SetFile::add(const std::string & p)
{
- _imp->handler->add(p);
+ return _imp->handler->add(p);
}
bool
diff --git a/paludis/set_file.hh b/paludis/set_file.hh
index 4a2fb84..1b86b88 100644
--- a/paludis/set_file.hh
+++ b/paludis/set_file.hh
@@ -137,8 +137,10 @@ namespace paludis
/**
* Add an item to our contents, if it is not there already.
+ *
+ * \since 0.49 returns whether any lines were added
*/
- void add(const std::string &);
+ bool add(const std::string &);
/**
* Remove any matching lines.