aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-10-13 05:57:05 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-10-13 05:57:05 +0000
commite0176aa160cf3565b2d2ce935dcda7f5153587bd (patch)
tree3fd612c2d7247ef4610a88164e8d900bac48befe
parentcbdb4346c06bd7ff410a307a884d3f743c1170e3 (diff)
downloadpaludis-e0176aa160cf3565b2d2ce935dcda7f5153587bd.tar.gz
paludis-e0176aa160cf3565b2d2ce935dcda7f5153587bd.tar.xz
Require 'ndbam.conf' in NDBAM repositories. Don't try to populate an NDBAM repository if the directory is not empty.
-rw-r--r--paludis/repositories/unpackaged/installed_unpackaged_repository.cc10
-rwxr-xr-xpaludis/repositories/unpackaged/installed_unpackaged_repository_TEST_setup.sh12
-rw-r--r--paludis/repositories/unpackaged/ndbam.cc36
-rw-r--r--paludis/repositories/unpackaged/ndbam.hh4
-rwxr-xr-xpaludis/repositories/unpackaged/unpackaged_repository_TEST_setup.sh3
5 files changed, 55 insertions, 10 deletions
diff --git a/paludis/repositories/unpackaged/installed_unpackaged_repository.cc b/paludis/repositories/unpackaged/installed_unpackaged_repository.cc
index a7e2cd4..a38d3e9 100644
--- a/paludis/repositories/unpackaged/installed_unpackaged_repository.cc
+++ b/paludis/repositories/unpackaged/installed_unpackaged_repository.cc
@@ -41,6 +41,14 @@ using namespace paludis::unpackaged_repositories;
#include <paludis/repositories/unpackaged/installed_unpackaged_repository-sr.cc>
+namespace
+{
+ bool supported_installed_unpackaged(const std::string & s)
+ {
+ return s == "installed_unpackaged-1";
+ }
+}
+
namespace paludis
{
template <>
@@ -51,7 +59,7 @@ namespace paludis
Implementation(const InstalledUnpackagedRepositoryParams & p) :
params(p),
- ndbam(p.location)
+ ndbam(p.location, &supported_installed_unpackaged, "installed_unpackaged-1")
{
}
};
diff --git a/paludis/repositories/unpackaged/installed_unpackaged_repository_TEST_setup.sh b/paludis/repositories/unpackaged/installed_unpackaged_repository_TEST_setup.sh
index 1018bca..55e650f 100755
--- a/paludis/repositories/unpackaged/installed_unpackaged_repository_TEST_setup.sh
+++ b/paludis/repositories/unpackaged/installed_unpackaged_repository_TEST_setup.sh
@@ -17,6 +17,10 @@ type=dir path=/stilton
type=file path=/stilton/cheese md5=1234567812345678 mtime=1234
type=file path=/stilton/is\ delicious md5=8765432187654321 mtime=2345
END
+cat <<"END" > repo1/ndbam.conf
+ndbam_format = 1
+repository_format = installed_unpackaged-1
+END
mkdir -p root2
cat <<"END" > root2/first
@@ -34,6 +38,10 @@ cat <<END > repo2/data/asdf/1.2.3:fred:ghjk/contents
type=file path=/first md5=c0ba8bfb6501abb1b7105ec79536b848 mtime=$(${PALUDIS_EBUILD_DIR}/utils/getmtime "root2/first")
type=file path=/first md5=0 mtime=$(${PALUDIS_EBUILD_DIR}/utils/getmtime "root2/second")
END
+cat <<"END" > repo2/ndbam.conf
+ndbam_format = 1
+repository_format = installed_unpackaged-1
+END
mkdir -p root3
mkdir -p repo3/indices/{categories/cat-one,packages/foo}
@@ -43,6 +51,10 @@ ln -s ../../../data/asdf repo3/indices/categories/cat-one/foo
ln -s ../../../data/asdf repo3/indices/packages/foo/cat-one
cat <<END > repo3/data/asdf/1.2.3:fred:ghjk/contents
END
+cat <<"END" > repo3/ndbam.conf
+ndbam_format = 1
+repository_format = installed_unpackaged-1
+END
mkdir -p root4
mkdir -p repo4
diff --git a/paludis/repositories/unpackaged/ndbam.cc b/paludis/repositories/unpackaged/ndbam.cc
index c6bb987..dbd2f06 100644
--- a/paludis/repositories/unpackaged/ndbam.cc
+++ b/paludis/repositories/unpackaged/ndbam.cc
@@ -36,6 +36,7 @@
#include <functional>
#include <vector>
#include <map>
+#include <fstream>
using namespace paludis;
using namespace paludis::unpackaged_repositories;
@@ -99,14 +100,37 @@ namespace paludis
};
}
-NDBAM::NDBAM(const FSEntry & l) :
+NDBAM::NDBAM(const FSEntry & l,
+ const tr1::function<bool (const std::string &)> & check_format,
+ const std::string & preferred_format) :
PrivateImplementationPattern<NDBAM>(new Implementation<NDBAM>(l))
{
- Context c("When creating skeleton NDBAM layout at '" + stringify(l) + "':");
- (l / "indices").mkdir();
- (l / "indices" / "categories").mkdir();
- (l / "indices" / "packages").mkdir();
- (l / "data").mkdir();
+ Context c("When checking NDBAM layout at '" + stringify(l) + "':");
+ if ((l / "ndbam.conf").exists())
+ {
+ Context cc("When reading '" + stringify(l / "ndbam.conf") + "':");
+ KeyValueConfigFile k(l / "ndbam.conf", KeyValueConfigFileOptions());
+ if (k.get("ndbam_format") != "1")
+ throw ConfigurationError("Unsupported NDBAM format '" + k.get("ndbam_format") + "'");
+ if (! check_format(k.get("repository_format")))
+ throw ConfigurationError("Unsupported NDBAM repository format '" + k.get("ndbam_format") + "'");
+ }
+ else if (DirIterator(l) != DirIterator())
+ throw ConfigurationError("No NDBAM repository found at '" + stringify(l) +
+ "', and it is not an empty directory");
+ else
+ {
+ Context cc("When creating skeleton NDBAM layout at '" + stringify(l) + "':");
+ (l / "indices").mkdir();
+ (l / "indices" / "categories").mkdir();
+ (l / "indices" / "packages").mkdir();
+ (l / "data").mkdir();
+ std::ofstream n(stringify(l / "ndbam.conf").c_str());
+ n << "ndbam_format = 1" << std::endl;
+ n << "repository_format = " << preferred_format << std::endl;
+ if (! n)
+ throw FSError("Could not write to '" + stringify(l / "ndbam.conf") + "'");
+ }
}
NDBAM::~NDBAM()
diff --git a/paludis/repositories/unpackaged/ndbam.hh b/paludis/repositories/unpackaged/ndbam.hh
index b5a0d86..51a39f8 100644
--- a/paludis/repositories/unpackaged/ndbam.hh
+++ b/paludis/repositories/unpackaged/ndbam.hh
@@ -44,7 +44,9 @@ namespace paludis
private PrivateImplementationPattern<NDBAM>
{
public:
- NDBAM(const FSEntry &);
+ NDBAM(const FSEntry &,
+ const tr1::function<bool (const std::string &)> & check_format,
+ const std::string & preferred_format);
~NDBAM();
tr1::shared_ptr<const CategoryNamePartSet> category_names()
diff --git a/paludis/repositories/unpackaged/unpackaged_repository_TEST_setup.sh b/paludis/repositories/unpackaged/unpackaged_repository_TEST_setup.sh
index 0ba4fb2..3c51723 100755
--- a/paludis/repositories/unpackaged/unpackaged_repository_TEST_setup.sh
+++ b/paludis/repositories/unpackaged/unpackaged_repository_TEST_setup.sh
@@ -10,6 +10,5 @@ This is the first file.
END
mkdir -p root
-
-mkdir -p installed/{indices/{categories,packages},data/}
+mkdir -p installed