1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-28 05:00:58 +01:00

Merged R9207

This commit is contained in:
Wouter den Breejen 2007-10-08 12:47:47 +00:00
parent 13b632ca57
commit ca3d96222a
29 changed files with 258 additions and 104 deletions

View file

@ -298,6 +298,17 @@ static Expr prim_getEnv(EvalState & state, const ATermVector & args)
return makeStr(getEnv(name));
}
/* for debugging purposes. print the first arg on stdout (perhaps stderr should be used?)
* and return the second
*/
static Expr prim_trace(EvalState & state, const ATermVector & args)
{
//string str = evalStringNoCtx(state, args[0]);
Expr a = evalExpr(state, args[0]);
printf("traced value: %s\n", atPrint(a).c_str());
return evalExpr(state, args[1]);
}
static Expr prim_relativise(EvalState & state, const ATermVector & args)
{
@ -892,6 +903,39 @@ static Expr prim_hasAttr(EvalState & state, const ATermVector & args)
}
/* takes
* param: list of { attr="attr"; value=value }
* returns an attribute set
* */
static Expr prim_listToAttrs(EvalState & state, const ATermVector & args)
{
try {
ATermMap res = ATermMap();
ATermList list;
list = evalList(state, args[0]);
for (ATermIterator i(list); i; ++i){
// *i should now contain a pointer to the list item expression
ATermList attrs;
Expr evaledExpr = evalExpr(state, *i);
if (matchAttrs(evaledExpr, attrs)){
Expr e = evalExpr(state, makeSelect(evaledExpr, toATerm("attr")));
string attr = evalStringNoCtx(state,e);
ATerm value;
Expr r = makeSelect(evaledExpr, toATerm("value"));
res.set(toATerm(attr), makeAttrRHS(r, makeNoPos()));
}
else {
throw EvalError(format("passed list item is a %s (value: %s). Set { attr=\"name\"; value=nix expr; } expected.") % showType(evaledExpr) % showValue(evaledExpr));
}
} // for
return makeAttrs(res);
} catch (Error & e) {
e.addPrefix(format("while calling listToAttrs "));
throw;
}
}
static Expr prim_removeAttrs(EvalState & state, const ATermVector & args)
{
ATermMap attrs;
@ -906,6 +950,12 @@ static Expr prim_removeAttrs(EvalState & state, const ATermVector & args)
return makeAttrs(attrs);
}
/* Determine whether the argument is a list. */
static Expr prim_isAttrs(EvalState & state, const ATermVector & args)
{
ATermList list;
return makeBool(matchAttrs(evalExpr(state, args[0]), list));
}
/*************************************************************
* Lists
@ -1049,6 +1099,7 @@ void EvalState::addPrimOps()
addPrimOp("abort", 1, prim_abort);
addPrimOp("throw", 1, prim_throw);
addPrimOp("__getEnv", 1, prim_getEnv);
addPrimOp("__trace", 2, prim_trace);
addPrimOp("relativise", 2, prim_relativise);
@ -1071,7 +1122,9 @@ void EvalState::addPrimOps()
addPrimOp("__attrNames", 1, prim_attrNames);
addPrimOp("__getAttr", 2, prim_getAttr);
addPrimOp("__hasAttr", 2, prim_hasAttr);
addPrimOp("__isAttrs", 1, prim_isAttrs);
addPrimOp("removeAttrs", 2, prim_removeAttrs);
addPrimOp("__listToAttrs", 1, prim_listToAttrs);
// Lists
addPrimOp("__isList", 1, prim_isList);

View file

@ -61,6 +61,8 @@ void createSymlink(const Path & link, const Path & target, bool careful)
/* Create directories up to `gcRoot'. */
createDirs(dirOf(link));
/* !!! shouldn't removing and creating the symlink be atomic? */
/* Remove the old symlink. */
if (pathExists(link)) {
if (careful && (!isLink(link) || !isInStore(readLink(link))))
@ -68,7 +70,7 @@ void createSymlink(const Path & link, const Path & target, bool careful)
unlink(link.c_str());
}
/* And create the new own. */
/* And create the new one. */
if (symlink(target.c_str(), link.c_str()) == -1)
throw SysError(format("symlinking `%1%' to `%2%'")
% link % target);

View file

@ -161,6 +161,7 @@ static TableId dbSharedState = 0;
static void upgradeStore07();
static void upgradeStore09();
static void upgradeStore11();
void checkStoreNotSymlink()
@ -245,6 +246,8 @@ LocalStore::LocalStore(bool reserveSpace)
upgradeStore07();
if (curSchema == 2)
upgradeStore09();
if (curSchema == 3)
upgradeStore11();
writeFile(schemaFN, (format("%1%") % nixSchemaVersion).str());
}
}
@ -1926,10 +1929,10 @@ static void upgradeStore09()
{
/* !!! we should disallow concurrent upgrades */
printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)...");
if (!pathExists(nixDBPath + "/referers")) return;
printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)...");
/*
Transaction txn(nixDB);
@ -1970,4 +1973,29 @@ static void upgradeStore09()
}
/* Upgrade from schema 3 (Nix 0.10) to schema 4 (Nix >= 0.11). The
only thing to do here is to delete the substitutes table and get
rid of invalid but substitutable references/referrers. */
static void upgradeStore11()
{
if (!pathExists(nixDBPath + "/substitutes")) return;
printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)...");
Transaction txn(nixDB);
TableId dbSubstitutes = nixDB.openTable("substitutes");
Paths subKeys;
nixDB.enumTable(txn, dbSubstitutes, subKeys);
for (Paths::iterator i = subKeys.begin(); i != subKeys.end(); ++i) {
if (!isValidPathTxn(txn, *i))
invalidateStorePath(txn, *i);
}
txn.commit();
nixDB.closeTable(dbSubstitutes);
nixDB.deleteTable("substitutes");
}
}

View file

@ -13,9 +13,9 @@ class Transaction;
/* Nix store and database schema version. Version 1 (or 0) was Nix <=
0.7. Version 2 was Nix 0.8 and 0.9. Version 3 is Nix 0.10 and
up. */
const int nixSchemaVersion = 3;
0.7. Version 2 was Nix 0.8 and 0.9. Version 3 is Nix 0.10.
Version 4 is Nix 0.11. */
const int nixSchemaVersion = 4;
extern string drvsLogDir;

View file

@ -161,10 +161,8 @@ void PathLocks::lockPaths(const PathSet & _paths, const string & waitMsg)
debug(format("locking path `%1%'") % path);
if (lockedPaths.find(lockPath) != lockedPaths.end()) {
debug(format("already holding lock on `%1%'") % lockPath);
continue;
}
if (lockedPaths.find(lockPath) != lockedPaths.end())
throw Error("deadlock: trying to re-acquire self-held lock");
AutoCloseFD fd;

View file

@ -10,27 +10,27 @@ namespace nix {
typedef enum {
wopQuit, //0
wopIsValidPath,
wopQuit = 0, //0
wopIsValidPath,
wopHasSubstitutes = 3,
wopIsValidStatePath,
wopIsValidComponentOrStatePath,
wopHasSubstitutes,
wopQueryPathHash,
wopQueryStatePathDrv,
wopQueryStoreReferences,
wopQueryStateReferences,
wopQueryStoreReferrers, //10
wopQueryStateReferrers,
wopQueryStoreReferrers,
wopQueryStateReferrers, //10
wopAddToStore,
wopAddTextToStore,
wopBuildDerivations, //14 TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! HANGS SOMETIMES !!!!!
wopBuildDerivations, //13
wopEnsurePath,
wopAddTempRoot,
wopAddIndirectRoot,
wopSyncWithGC,
wopFindRoots,
wopCollectGarbage, //20
wopExportPath,
wopCollectGarbage,
wopExportPath, //20
wopImportPath,
wopQueryDeriver,
wopQueryDerivers,
@ -39,15 +39,15 @@ typedef enum {
wopIsStateComponent,
wopStorePathRequisites,
wopSetStateRevisions,
wopQueryStateRevisions, //30
wopQueryAvailableStateRevisions,
wopQueryStateRevisions,
wopQueryAvailableStateRevisions, //30
wopCommitStatePath,
wopScanAndUpdateAllReferences,
wopGetSharedWith,
wopToNonSharedPathSet,
wopRevertToRevision,
wopShareState,
wopUnShareState,
wopUnShareState, //37
} WorkerOp;