aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/local-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-01-29 18:17:36 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-01-29 18:17:36 +0000
commit66c51dc21558c6ac5149c5158df7e5b580029e84 (patch)
tree455b9e454c24e0c9d132f8881098e5d240250928 /src/libstore/local-store.cc
parent5b5a3af98372029f3a870cf18cc1442f1434be85 (diff)
* nix-store --dump-db / --load-db to dump/load the Nix DB.
* nix-store --register-validity: option to supply the content hash of each path. * Removed compatibility with Nix <= 0.7 stores.
Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r--src/libstore/local-store.cc106
1 files changed, 13 insertions, 93 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 7b3b7355e..12a73b70c 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -56,7 +56,6 @@ static TableId dbReferrers = 0;
static TableId dbDerivers = 0;
-static void upgradeStore07();
static void upgradeStore09();
static void upgradeStore11();
@@ -128,12 +127,12 @@ LocalStore::LocalStore(bool reserveSpace)
% curSchema % nixSchemaVersion);
if (curSchema < nixSchemaVersion) {
+ if (curSchema == 0) /* new store */
+ curSchema = nixSchemaVersion;
if (curSchema <= 1)
- upgradeStore07();
- if (curSchema == 2)
- upgradeStore09();
- if (curSchema == 3)
- upgradeStore11();
+ throw Error("your Nix store is no longer supported");
+ if (curSchema <= 2) upgradeStore09();
+ if (curSchema <= 3) upgradeStore11();
writeFile(schemaFN, (format("%1%") % nixSchemaVersion).str());
}
}
@@ -261,6 +260,14 @@ bool LocalStore::isValidPath(const Path & path)
}
+PathSet LocalStore::queryValidPaths()
+{
+ Paths paths;
+ nixDB.enumTable(noTxn, dbValidPaths, paths);
+ return PathSet(paths.begin(), paths.end());
+}
+
+
static string addPrefix(const string & prefix, const string & s)
{
return prefix + string(1, (char) 0) + s;
@@ -1069,93 +1076,6 @@ void LocalStore::optimiseStore(bool dryRun, OptimiseStats & stats)
}
-/* Upgrade from schema 1 (Nix <= 0.7) to schema 2 (Nix >= 0.8). */
-static void upgradeStore07()
-{
- printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)...");
-
- Transaction txn(nixDB);
-
- Paths validPaths2;
- nixDB.enumTable(txn, dbValidPaths, validPaths2);
- PathSet validPaths(validPaths2.begin(), validPaths2.end());
-
- std::cerr << "hashing paths...";
- int n = 0;
- for (PathSet::iterator i = validPaths.begin(); i != validPaths.end(); ++i) {
- checkInterrupt();
- string s;
- nixDB.queryString(txn, dbValidPaths, *i, s);
- if (s == "") {
- Hash hash = hashPath(htSHA256, *i);
- setHash(txn, *i, hash);
- std::cerr << ".";
- if (++n % 1000 == 0) {
- txn.commit();
- txn.begin(nixDB);
- }
- }
- }
- std::cerr << std::endl;
-
- txn.commit();
-
- txn.begin(nixDB);
-
- std::cerr << "processing closures...";
- for (PathSet::iterator i = validPaths.begin(); i != validPaths.end(); ++i) {
- checkInterrupt();
- if (i->size() > 6 && string(*i, i->size() - 6) == ".store") {
- ATerm t = ATreadFromNamedFile(i->c_str());
- if (!t) throw Error(format("cannot read aterm from `%1%'") % *i);
-
- ATermList roots, elems;
- if (!matchOldClosure(t, roots, elems)) continue;
-
- for (ATermIterator j(elems); j; ++j) {
-
- ATerm path2;
- ATermList references2;
- if (!matchOldClosureElem(*j, path2, references2)) continue;
-
- Path path = aterm2String(path2);
- if (validPaths.find(path) == validPaths.end())
- /* Skip this path; it's invalid. This is a normal
- condition (Nix <= 0.7 did not enforce closure
- on closure store expressions). */
- continue;
-
- PathSet references;
- for (ATermIterator k(references2); k; ++k) {
- Path reference = aterm2String(*k);
- if (validPaths.find(reference) == validPaths.end())
- /* Bad reference. Set it anyway and let the
- user fix it. */
- printMsg(lvlError, format("closure `%1%' contains reference from `%2%' "
- "to invalid path `%3%' (run `nix-store --verify')")
- % *i % path % reference);
- references.insert(reference);
- }
-
- PathSet prevReferences;
- queryReferences(txn, path, prevReferences);
- if (prevReferences.size() > 0 && references != prevReferences)
- printMsg(lvlError, format("warning: conflicting references for `%1%'") % path);
-
- if (references != prevReferences)
- setReferences(txn, path, references);
- }
-
- std::cerr << ".";
- }
- }
- std::cerr << std::endl;
-
- /* !!! maybe this transaction is way too big */
- txn.commit();
-}
-
-
/* Upgrade from schema 2 (0.8 <= Nix <= 0.9) to schema 3 (Nix >=
0.10). The only thing to do here is to upgrade the old `referer'
table (which causes quadratic complexity in some cases) to the new