aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-28 21:24:26 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-28 21:24:26 +0000
commit3d9f664cdc0a5d72af12e0dd618f3c9112ad24ab (patch)
tree17df2149c7084c1a886f2b98cb35a450fd13ea1a
parent3f222cab4150e1b7aea7e528525b63427ff62871 (diff)
downloadpaludis-3d9f664cdc0a5d72af12e0dd618f3c9112ad24ab.tar.gz
paludis-3d9f664cdc0a5d72af12e0dd618f3c9112ad24ab.tar.xz
Move some common merge / unmerge code into separate files.
-rw-r--r--ebuild/utils/Makefile.am4
-rw-r--r--ebuild/utils/merge.cc51
-rw-r--r--ebuild/utils/merge_common.cc83
-rw-r--r--ebuild/utils/merge_common.hh50
-rw-r--r--ebuild/utils/unmerge.cc50
5 files changed, 143 insertions, 95 deletions
diff --git a/ebuild/utils/Makefile.am b/ebuild/utils/Makefile.am
index 03bb652..81b7095 100644
--- a/ebuild/utils/Makefile.am
+++ b/ebuild/utils/Makefile.am
@@ -49,13 +49,13 @@ libexecprog_SCRIPTS = \
libexecprog_PROGRAMS = merge unmerge
AM_CXXFLAGS = -I$(top_srcdir)
-merge_SOURCES = merge.cc
+merge_SOURCES = merge.cc merge_common.cc merge_common.hh
merge_LDADD = \
$(top_builddir)/paludis/libpaludis.a \
$(top_builddir)/paludis/args/libpaludisargs.a \
$(top_builddir)/paludis/util/libpaludisutil.a
-unmerge_SOURCES = unmerge.cc
+unmerge_SOURCES = unmerge.cc merge_common.cc merge_common.hh
unmerge_LDADD = \
$(top_builddir)/paludis/libpaludis.a \
$(top_builddir)/paludis/args/libpaludisargs.a \
diff --git a/ebuild/utils/merge.cc b/ebuild/utils/merge.cc
index 9ee9f18..a49c87b 100644
--- a/ebuild/utils/merge.cc
+++ b/ebuild/utils/merge.cc
@@ -17,6 +17,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "merge_common.hh"
+
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/log.hh>
@@ -42,6 +44,8 @@
#include <sys/types.h>
using namespace paludis;
+using namespace merge;
+
using std::cout;
using std::cerr;
using std::endl;
@@ -50,57 +54,10 @@ using std::ofstream;
using std::istreambuf_iterator;
using std::ostreambuf_iterator;
-
namespace
{
int exit_status;
- struct Failure
- {
- std::string message;
-
- Failure(const std::string & m) :
- message(m)
- {
- };
- };
-
- std::vector<std::string>
- get_config_var(const std::string & var)
- {
- std::vector<std::string> result;
- WhitespaceTokeniser::get_instance()->tokenise(getenv_with_default(var, ""),
- std::back_inserter(result));
- return result;
- }
-
- bool
- is_config_protected(const FSEntry & root, const FSEntry & file)
- {
- static std::vector<std::string> cfg_pro(get_config_var("CONFIG_PROTECT")),
- cfg_pro_mask(get_config_var("CONFIG_PROTECT_MASK"));
-
- std::string file_str(stringify(file)), root_str(stringify(root));
- if (0 != file_str.compare(0, root_str.length(), root_str))
- throw Failure("is_config_protected confused: '" + root_str + "' '" + file_str + "'");
- file_str.erase(0, root_str.length());
- if (file_str.empty())
- file_str = "/";
-
- bool result(false);
- for (std::vector<std::string>::const_iterator c(cfg_pro.begin()),
- c_end(cfg_pro.end()) ; c != c_end && ! result ; ++c)
- if (0 == fnmatch((*c + "/*").c_str(), file_str.c_str(), 0))
- result = true;
-
- for (std::vector<std::string>::const_iterator c(cfg_pro_mask.begin()),
- c_end(cfg_pro_mask.end()) ; c != c_end && result ; ++c)
- if (0 == fnmatch((*c + "/*").c_str(), file_str.c_str(), 0))
- result = false;
-
- return result;
- }
-
FSEntry
make_config_protect_name(const FSEntry & name, const FSEntry & file_to_install)
{
diff --git a/ebuild/utils/merge_common.cc b/ebuild/utils/merge_common.cc
new file mode 100644
index 0000000..abb42a2
--- /dev/null
+++ b/ebuild/utils/merge_common.cc
@@ -0,0 +1,83 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "merge_common.hh"
+
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/pstream.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/strip.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <algorithm>
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+#include <iterator>
+#include <string>
+#include <vector>
+
+#include <cstdlib>
+#include <errno.h>
+#include <fcntl.h>
+#include <fnmatch.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+using namespace paludis;
+
+std::vector<std::string>
+merge::get_config_var(const std::string & var)
+{
+ std::vector<std::string> result;
+ WhitespaceTokeniser::get_instance()->tokenise(getenv_with_default(var, ""),
+ std::back_inserter(result));
+ return result;
+}
+
+bool
+merge::is_config_protected(const FSEntry & root, const FSEntry & file)
+{
+ static std::vector<std::string> cfg_pro(get_config_var("CONFIG_PROTECT")),
+ cfg_pro_mask(get_config_var("CONFIG_PROTECT_MASK"));
+
+ std::string file_str(stringify(file)), root_str(stringify(root));
+ if (0 != file_str.compare(0, root_str.length(), root_str))
+ throw Failure("is_config_protected confused: '" + root_str + "' '" + file_str + "'");
+ file_str.erase(0, root_str.length());
+ if (file_str.empty())
+ file_str = "/";
+
+ bool result(false);
+ for (std::vector<std::string>::const_iterator c(cfg_pro.begin()),
+ c_end(cfg_pro.end()) ; c != c_end && ! result ; ++c)
+ if (0 == fnmatch((*c + "/*").c_str(), file_str.c_str(), 0))
+ result = true;
+
+ for (std::vector<std::string>::const_iterator c(cfg_pro_mask.begin()),
+ c_end(cfg_pro_mask.end()) ; c != c_end && result ; ++c)
+ if (0 == fnmatch((*c + "/*").c_str(), file_str.c_str(), 0))
+ result = false;
+
+ return result;
+}
+
diff --git a/ebuild/utils/merge_common.hh b/ebuild/utils/merge_common.hh
new file mode 100644
index 0000000..5e0e247
--- /dev/null
+++ b/ebuild/utils/merge_common.hh
@@ -0,0 +1,50 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_EBUILD_UTILS_MERGE_COMMON_HH
+#define PALUDIS_GUARD_EBUILD_UTILS_MERGE_COMMON_HH 1
+
+#include <string>
+#include <vector>
+
+namespace paludis
+{
+ class FSEntry;
+}
+
+namespace merge
+{
+ struct Failure
+ {
+ std::string message;
+
+ Failure(const std::string & m) :
+ message(m)
+ {
+ };
+ };
+
+ std::vector<std::string>
+ get_config_var(const std::string & var);
+
+ bool
+ is_config_protected(const paludis::FSEntry & root, const paludis::FSEntry & file);
+}
+
+#endif
diff --git a/ebuild/utils/unmerge.cc b/ebuild/utils/unmerge.cc
index 118f376..f17c3c5 100644
--- a/ebuild/utils/unmerge.cc
+++ b/ebuild/utils/unmerge.cc
@@ -17,6 +17,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "merge_common.hh"
+
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/log.hh>
@@ -43,6 +45,8 @@
#include <sys/types.h>
using namespace paludis;
+using namespace merge;
+
using std::cout;
using std::cerr;
using std::endl;
@@ -52,52 +56,6 @@ namespace
{
int exit_status;
- struct Failure
- {
- std::string message;
-
- Failure(const std::string & m) :
- message(m)
- {
- };
- };
-
- std::vector<std::string>
- get_config_var(const std::string & var)
- {
- std::vector<std::string> result;
- WhitespaceTokeniser::get_instance()->tokenise(getenv_with_default(var, ""),
- std::back_inserter(result));
- return result;
- }
-
- bool
- is_config_protected(const FSEntry & root, const FSEntry & file)
- {
- static std::vector<std::string> cfg_pro(get_config_var("CONFIG_PROTECT")),
- cfg_pro_mask(get_config_var("CONFIG_PROTECT_MASK"));
-
- std::string file_str(stringify(file)), root_str(stringify(root));
- if (0 != file_str.compare(0, root_str.length(), root_str))
- throw Failure("is_config_protected confused: '" + root_str + "' '" + file_str + "'");
- file_str.erase(0, root_str.length());
- if (file_str.empty())
- file_str = "/";
-
- bool result(false);
- for (std::vector<std::string>::const_iterator c(cfg_pro.begin()),
- c_end(cfg_pro.end()) ; c != c_end && ! result ; ++c)
- if (0 == fnmatch((*c + "/*").c_str(), file_str.c_str(), 0))
- result = true;
-
- for (std::vector<std::string>::const_iterator c(cfg_pro_mask.begin()),
- c_end(cfg_pro_mask.end()) ; c != c_end && result ; ++c)
- if (0 == fnmatch((*c + "/*").c_str(), file_str.c_str(), 0))
- result = false;
-
- return result;
- }
-
template <typename Iter_>
void unmerge_contents(const FSEntry & root, const Iter_ begin, const Iter_ end)
{