aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-11-22 18:45:56 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-11-22 18:45:56 +0000
commitab0bc4999a49efbc8e1c25989662a96e32fa0cc5 (patch)
tree3864cf300fccb46a97decd2d00b8176c047a87d0 /src/libstore
parent40d9eb14dfb842c51e9f86818b43ae7711e1a5d6 (diff)
* Maintain integrity of the substitute and successor mappings when
deleting a path in the store. * Allow absolute paths in Nix expressions. * Get nix-prefetch-url to work again. * Various other fixes.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/normalise.cc1
-rw-r--r--src/libstore/store.cc91
-rw-r--r--src/libstore/store.hh3
3 files changed, 55 insertions, 40 deletions
diff --git a/src/libstore/normalise.cc b/src/libstore/normalise.cc
index db85c3b5b..7ef45e292 100644
--- a/src/libstore/normalise.cc
+++ b/src/libstore/normalise.cc
@@ -82,6 +82,7 @@ Path normaliseStoreExpr(const Path & _nePath, PathSet pending)
debug(format("skipping build of expression `%1%', someone beat us to it")
% (string) nePath);
if (ne.type != StoreExpr::neClosure) abort();
+ outputLocks.setDeletion(true);
return nePath2;
}
}
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index caaa293a6..4c6b8bbec 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -243,16 +243,33 @@ bool isValidPath(const Path & path)
}
-void unregisterValidPath(const Path & _path)
+static void invalidatePath(const Path & path, Transaction & txn)
{
- Path path(canonPath(_path));
- Transaction txn(nixDB);
-
debug(format("unregistering path `%1%'") % path);
nixDB.delPair(txn, dbValidPaths, path);
- txn.commit();
+ /* Remove any successor mappings to this path (but not *from*
+ it). */
+ Paths revs;
+ nixDB.queryStrings(txn, dbSuccessorsRev, path, revs);
+ for (Paths::iterator i = revs.begin(); i != revs.end(); ++i)
+ nixDB.delPair(txn, dbSuccessors, *i);
+ nixDB.delPair(txn, dbSuccessorsRev, path);
+
+ /* Remove any substitute mappings to this path. */
+ revs.clear();
+ nixDB.queryStrings(txn, dbSubstitutesRev, path, revs);
+ for (Paths::iterator i = revs.begin(); i != revs.end(); ++i) {
+ Paths subs;
+ nixDB.queryStrings(txn, dbSubstitutes, *i, subs);
+ remove(subs.begin(), subs.end(), path);
+ if (subs.size() > 0)
+ nixDB.setStrings(txn, dbSubstitutes, *i, subs);
+ else
+ nixDB.delPair(txn, dbSubstitutes, *i);
+ }
+ nixDB.delPair(txn, dbSubstitutesRev, path);
}
@@ -289,6 +306,8 @@ Path addToStore(const Path & _srcPath)
registerValidPath(txn, dstPath);
txn.commit();
}
+
+ outputLock.setDeletion(true);
}
return dstPath;
@@ -310,6 +329,8 @@ void addTextToStore(const Path & dstPath, const string & s)
registerValidPath(txn, dstPath);
txn.commit();
}
+
+ outputLock.setDeletion(true);
}
}
@@ -321,7 +342,9 @@ void deleteFromStore(const Path & _path)
if (!isInPrefix(path, nixStore))
throw Error(format("path `%1%' is not in the store") % path);
- unregisterValidPath(path);
+ Transaction txn(nixDB);
+ invalidatePath(path, txn);
+ txn.commit();
deletePath(path);
}
@@ -332,50 +355,43 @@ void verifyStore()
Transaction txn(nixDB);
Paths paths;
+ PathSet validPaths;
nixDB.enumTable(txn, dbValidPaths, paths);
- for (Paths::iterator i = paths.begin();
- i != paths.end(); i++)
+ for (Paths::iterator i = paths.begin(); i != paths.end(); ++i)
{
Path path = *i;
if (!pathExists(path)) {
debug(format("path `%1%' disappeared") % path);
- nixDB.delPair(txn, dbValidPaths, path);
- nixDB.delPair(txn, dbSuccessorsRev, path);
- nixDB.delPair(txn, dbSubstitutesRev, path);
- }
+ invalidatePath(path, txn);
+ } else
+ validPaths.insert(path);
}
-#if 0
- Strings subs;
- nixDB.enumTable(txn, dbSubstitutes, subs);
-
- for (Strings::iterator i = subs.begin();
- i != subs.end(); i++)
- {
- FSId srcId = parseHash(*i);
-
- Strings subIds;
- nixDB.queryStrings(txn, dbSubstitutes, srcId, subIds);
-
- for (Strings::iterator j = subIds.begin();
- j != subIds.end(); )
+ Paths sucs;
+ nixDB.enumTable(txn, dbSuccessors, sucs);
+ for (Paths::iterator i = sucs.begin(); i != sucs.end(); ++i) {
+ /* Note that *i itself does not have to be valid, just its
+ successor. */
+ Path sucPath;
+ if (nixDB.queryString(txn, dbSuccessors, *i, sucPath) &&
+ validPaths.find(sucPath) == validPaths.end())
{
- FSId subId = parseHash(*j);
-
- Strings subPaths;
- nixDB.queryStrings(txn, dbId2Paths, subId, subPaths);
- if (subPaths.size() == 0) {
- debug(format("erasing substitute %1% for %2%")
- % (string) subId % (string) srcId);
- j = subIds.erase(j);
- } else j++;
+ debug(format("found successor mapping to non-existent path `%1%'") % sucPath);
+ nixDB.delPair(txn, dbSuccessors, *i);
}
+ }
- nixDB.setStrings(txn, dbSubstitutes, srcId, subIds);
+ Paths rsucs;
+ nixDB.enumTable(txn, dbSuccessorsRev, rsucs);
+ for (Paths::iterator i = rsucs.begin(); i != rsucs.end(); ++i) {
+ if (validPaths.find(*i) == validPaths.end()) {
+ debug(format("found reverse successor mapping for non-existent path `%1%'") % *i);
+ nixDB.delPair(txn, dbSuccessorsRev, *i);
+ }
}
-#endif
+#if 0
Paths sucs;
nixDB.enumTable(txn, dbSuccessors, sucs);
@@ -395,6 +411,7 @@ void verifyStore()
nixDB.setStrings(txn, dbSuccessorsRev, sucPath, revs);
}
}
+#endif
txn.commit();
}
diff --git a/src/libstore/store.hh b/src/libstore/store.hh
index dab3d603f..143cad8db 100644
--- a/src/libstore/store.hh
+++ b/src/libstore/store.hh
@@ -48,9 +48,6 @@ Paths querySubstitutes(const Path & srcPath);
/* Register the validity of a path. */
void registerValidPath(const Transaction & txn, const Path & path);
-/* Unregister the validity of a path. */
-void unregisterValidPath(const Path & path);
-
/* Checks whether a path is valid. */
bool isValidPath(const Path & path);