aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-05-17 09:54:27 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-05-17 09:54:27 +0100
commit16d0f528e226e88b28286d8b52a49dbb41ad752b (patch)
tree9417f2161261b1ba7cd3115ff67b3a885465bd09
parentf5d6720601d520087d16cda5535662451e799e6e (diff)
downloadpaludis-16d0f528e226e88b28286d8b52a49dbb41ad752b.tar.gz
paludis-16d0f528e226e88b28286d8b52a49dbb41ad752b.tar.xz
Return whether SetFile::remove removed things
-rw-r--r--paludis/set_file.cc47
-rw-r--r--paludis/set_file.hh6
-rw-r--r--paludis/set_file_TEST.cc12
3 files changed, 45 insertions, 20 deletions
diff --git a/paludis/set_file.cc b/paludis/set_file.cc
index d00a292..a8c7442 100644
--- a/paludis/set_file.cc
+++ b/paludis/set_file.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -59,7 +59,7 @@ namespace
virtual std::tr1::shared_ptr<SetSpecTree> contents() const = 0;
virtual void add(const std::string &) = 0;
- virtual void remove(const std::string &) = 0;
+ virtual bool remove(const std::string &) = 0;
virtual void rewrite() const = 0;
};
@@ -80,7 +80,7 @@ namespace
virtual std::tr1::shared_ptr<SetSpecTree> contents() const;
virtual void add(const std::string &);
- virtual void remove(const std::string &);
+ virtual bool remove(const std::string &);
virtual void rewrite() const;
};
@@ -96,7 +96,7 @@ namespace
virtual std::tr1::shared_ptr<SetSpecTree> contents() const;
virtual void add(const std::string &) PALUDIS_ATTRIBUTE((noreturn));
- virtual void remove(const std::string &) PALUDIS_ATTRIBUTE((noreturn));
+ virtual bool remove(const std::string &) PALUDIS_ATTRIBUTE((noreturn));
virtual void rewrite() const PALUDIS_ATTRIBUTE((noreturn));
};
@@ -117,7 +117,7 @@ namespace
virtual std::tr1::shared_ptr<SetSpecTree> contents() const;
virtual void add(const std::string &);
- virtual void remove(const std::string &);
+ virtual bool remove(const std::string &);
virtual void rewrite() const;
};
@@ -383,7 +383,7 @@ SimpleHandler::add(const std::string & p)
_contents.reset();
}
-void
+bool
SimpleHandler::remove(const std::string & p)
{
Lock l(_mutex);
@@ -391,7 +391,19 @@ SimpleHandler::remove(const std::string & p)
Context context("When removing '" + stringify(p) + "' from simple set file '" + stringify(_p.file_name()) + "':");
_contents.reset();
- _lines.remove(p);
+
+ bool result(false);
+ for (std::list<std::string>::iterator i(_lines.begin()), i_end(_lines.end()) ;
+ i != i_end ; )
+ if (*i == p)
+ {
+ result = true;
+ _lines.erase(i++);
+ }
+ else
+ ++i;
+
+ return result;
}
void
@@ -461,15 +473,26 @@ PaludisConfHandler::add(const std::string & p)
_contents.reset();
}
-void
+bool
PaludisConfHandler::remove(const std::string & p)
{
Context context("When removing '" + stringify(p) + "' from paludis conf set file '" + stringify(_p.file_name()) + "':");
Lock l(_mutex);
-
_contents.reset();
- _lines.remove_if(TokenOneIs(p));
+
+ bool result(false);
+ for (std::list<std::string>::iterator i(_lines.begin()), i_end(_lines.end()) ;
+ i != i_end ; )
+ if (TokenOneIs(p)(*i))
+ {
+ result = true;
+ _lines.erase(i++);
+ }
+ else
+ ++i;
+
+ return result;
}
void
@@ -538,7 +561,7 @@ PaludisBashHandler::add(const std::string & p)
throw SetFileError(_p.file_name(), "Cannot add entry '" + p + "' to bash script '" + stringify(_p.file_name()) + "'");
}
-void
+bool
PaludisBashHandler::remove(const std::string & p)
{
throw SetFileError(_p.file_name(), "Cannot remove entry '" + p + "' from bash script '" + stringify(_p.file_name()) + "'");
@@ -593,7 +616,7 @@ SetFile::add(const std::string & p)
_imp->handler->add(p);
}
-void
+bool
SetFile::remove(const std::string & p)
{
return _imp->handler->remove(p);
diff --git a/paludis/set_file.hh b/paludis/set_file.hh
index 3954df9..fb28ef3 100644
--- a/paludis/set_file.hh
+++ b/paludis/set_file.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -142,8 +142,10 @@ namespace paludis
/**
* Remove any matching lines.
+ *
+ * \since 0.48 returns whether any lines were removed
*/
- void remove(const std::string &);
+ bool remove(const std::string &);
};
/**
diff --git a/paludis/set_file_TEST.cc b/paludis/set_file_TEST.cc
index 07607de..ec59709 100644
--- a/paludis/set_file_TEST.cc
+++ b/paludis/set_file_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -101,8 +101,8 @@ namespace test_cases
TEST_CHECK_EQUAL(g, "# this is a comment\n\nfoo/bar\n>=bar/baz-1.23\n\n# the end\nmoo/oink\n");
}
- f.remove(">=bar/baz-1.23");
- f.remove("bar/cow");
+ TEST_CHECK(f.remove(">=bar/baz-1.23"));
+ TEST_CHECK(! f.remove("bar/cow"));
{
SetSpecStringifier p;
@@ -170,9 +170,9 @@ namespace test_cases
TEST_CHECK_EQUAL(g, "# this is a comment\n\n? foo/bar\n* >=bar/baz-1.23\n\n* set\n? settee\n\n# the end\n* moo/oink\n* couch\n");
}
- f.remove(">=bar/baz-1.23");
- f.remove("bar/cow");
- f.remove("set");
+ TEST_CHECK(f.remove(">=bar/baz-1.23"));
+ TEST_CHECK(! f.remove("bar/cow"));
+ TEST_CHECK(f.remove("set"));
{
SetSpecStringifier p;