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

Before editting get-drvs.hh: DrvInfo

This commit is contained in:
Wouter den Breejen 2007-06-21 13:26:58 +00:00
parent 235c91dd7f
commit a4fda31ad5
12 changed files with 164 additions and 52 deletions

View file

@ -1686,9 +1686,7 @@ void DerivationGoal::computeClosure()
/* For this output path, find the references to other paths contained in it. */
PathSet references = scanForReferences(path, allPaths);
/* For debugging, print out the referenced and unreferenced
paths. */
for (PathSet::iterator i = inputPaths.begin();
@ -1703,7 +1701,6 @@ void DerivationGoal::computeClosure()
allReferences[path] = references;
/* If the derivation specifies an `allowedReferences'
attribute (containing a list of paths that the output may
refer to), check that all references are in that list. !!!
@ -1746,15 +1743,18 @@ void DerivationGoal::computeClosure()
}
/*
* TODO COMMENT
*
*
* We first register alls paths as valid, and only scan for component references.
* Now that those paths are registered as valid, we're able to call queryDeriversStatePath
*
* We already scanned for Component references in Component paths
* Now we scan in Component paths for state references
*
* If state is enabled for the path we:
* scan for and state references and component references in the state path
*/
for (DerivationOutputs::iterator i = drv.outputs.begin();
i != drv.outputs.end(); ++i)
//TODO we scan for each output, be then we do multiple scans inside for the state path .....
for (DerivationOutputs::iterator i = drv.outputs.begin(); i != drv.outputs.end(); ++i)
{
Path path = i->second.path;
@ -1766,23 +1766,32 @@ void DerivationGoal::computeClosure()
for (PathSet::const_iterator i = allPaths.begin(); i != allPaths.end(); i++){
Path componentPath = *i;
//printMsg(lvlError, format("COMP: %1%") % (*i));
if(isStateComponentTxn(txn, componentPath)){
printMsg(lvlError, format("COMP-STATE: %1%") % (*i));
//printMsg(lvlError, format("Scanning for state path: %1%") % (*i));
PathSet stateRefs = queryDeriversStatePath(txn, componentPath ,"*",getCallingUserName());
allStatePaths = mergePathSets(stateRefs, allStatePaths);
}
}
PathSet stateReferences = scanForStateReferences(path, allStatePaths);
//We scan for state references in the component path
PathSet all_state_references = scanForStateReferences(path, allStatePaths);
//If state is enabled: Seaches for state and component references in the state path
if(isStateDrvTxn(txn, drv)){
Path statePath = drv.stateOutputs.find("state")->second.statepath;
PathSet state_references = scanForReferences(statePath, allPaths);
PathSet state_stateReferences = scanForStateReferences(statePath, allStatePaths);
all_state_references = mergePathSets(all_state_references, mergePathSets(state_references, state_stateReferences));
}
for (PathSet::const_iterator i = allStatePaths.begin(); i != allStatePaths.end(); i++){
debug(format("all possible StatePaths: %1%") % (*i));
}
for (PathSet::const_iterator i = stateReferences.begin(); i != stateReferences.end(); i++){
for (PathSet::const_iterator i = all_state_references.begin(); i != all_state_references.end(); i++){
debug(format("state References scanned: %1%") % (*i));
}
allStateReferences[path] = stateReferences;
allStateReferences[path] = all_state_references;
}
for (DerivationOutputs::iterator i = drv.outputs.begin();

View file

@ -21,14 +21,13 @@ Path writeDerivation(const Derivation & drv, const string & name)
{
PathSet references;
references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
for (DerivationInputs::const_iterator i = drv.inputDrvs.begin();
i != drv.inputDrvs.end(); ++i)
for (DerivationInputs::const_iterator i = drv.inputDrvs.begin(); i != drv.inputDrvs.end(); ++i)
references.insert(i->first);
/* Note that the outputs of a derivation are *not* references
(that can be missing (of course) and should not necessarily be
held during a garbage collection). */
//TODO TODO TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//We only need to hash over inputSrcs and inputDrvs (I think ...)
PathSet stateReferences;
string suffix = name + drvExtension;

View file

@ -44,7 +44,7 @@ static TableId dbValidPaths = 0;
paths. */
static TableId dbReferences = 0;
/* dbReferences :: Path -> [Path]
/* dbStateReferences :: Path -> [Path]
This table lists the outgoing file system state references for each
output path that has been built by a Nix derivation. These are
@ -60,6 +60,13 @@ static TableId dbStateReferences = 0;
referrer. */
static TableId dbReferrers = 0;
/* dbStateReferrers :: Path -> Path
This table is just the reverse mapping of dbStateReferences. This table
can have duplicate keys, each corresponding value denoting a single
referrer. */
static TableId dbStateReferrers = 0;
/* dbSubstitutes :: Path -> [[Path]]
Each pair $(p, subs)$ tells Nix that it can use any of the
@ -159,12 +166,13 @@ LocalStore::LocalStore(bool reserveSpace)
}
dbValidPaths = nixDB.openTable("validpaths");
dbReferences = nixDB.openTable("references");
dbReferrers = nixDB.openTable("referrers", true); /* must be sorted */ //TODO ADD STATE REFERERS?
dbReferrers = nixDB.openTable("referrers", true); /* must be sorted */
dbSubstitutes = nixDB.openTable("substitutes");
dbDerivers = nixDB.openTable("derivers");
dbStateInfo = nixDB.openTable("stateinfo");
dbStateCounters = nixDB.openTable("statecounters");
dbStateReferences = nixDB.openTable("references_state");
dbStateReferrers = nixDB.openTable("referrers_state", true); /* must be sorted */
int curSchema = 0;
Path schemaFN = nixDBPath + "/schema";
@ -344,6 +352,16 @@ static PathSet getReferrers(const Transaction & txn, const Path & storePath)
return referrers;
}
static PathSet getStateReferrers(const Transaction & txn, const Path & storePath) //TODO this is just a copy of getReferrers, maybe make the function more generic?
{
PathSet referrers;
Strings keys;
nixDB.enumTable(txn, dbStateReferrers, keys, storePath + string(1, (char) 0));
for (Strings::iterator i = keys.begin(); i != keys.end(); ++i)
referrers.insert(stripPrefix(storePath, *i));
return referrers;
}
void setReferences(const Transaction & txn, const Path & storePath,
const PathSet & references, const PathSet & stateReferences)
{
@ -369,20 +387,25 @@ void setReferences(const Transaction & txn, const Path & storePath,
nixDB.setStrings(txn, dbStateReferences, storePath,
Paths(stateReferences.begin(), stateReferences.end()));
//TODO THESE 2 ALSO FOR STATEREFS
/* Update the referrers mappings of all new referenced paths. */
for (PathSet::const_iterator i = references.begin();
i != references.end(); ++i)
for (PathSet::const_iterator i = references.begin(); i != references.end(); ++i)
if (oldReferences2.find(*i) == oldReferences2.end())
nixDB.setString(txn, dbReferrers, addPrefix(*i, storePath), "");
/* Remove referrer mappings from paths that are no longer
references. */
for (Paths::iterator i = oldReferences.begin();
i != oldReferences.end(); ++i)
/* Update the state referrers mappings of all new referenced paths. */
for (PathSet::const_iterator i = stateReferences.begin(); i != stateReferences.end(); ++i)
if (oldStateReferences2.find(*i) == oldStateReferences2.end())
nixDB.setString(txn, dbStateReferrers, addPrefix(*i, storePath), "");
/* Remove referrer mappings from paths that are no longer references. */
for (Paths::iterator i = oldReferences.begin(); i != oldReferences.end(); ++i)
if (references.find(*i) == references.end())
nixDB.delPair(txn, dbReferrers, addPrefix(*i, storePath));
/* Remove referrer mappings from paths that are no longer state references. */
for (Paths::iterator i = oldStateReferences.begin(); i != oldStateReferences.end(); ++i)
if (stateReferences.find(*i) == stateReferences.end())
nixDB.delPair(txn, dbStateReferrers, addPrefix(*i, storePath));
}
@ -415,15 +438,11 @@ void queryStateReferences(const Transaction & txn,
stateReferences.insert(stateReferences2.begin(), stateReferences2.end());
}
void LocalStore::queryStateReferences(const Path & storePath,
PathSet & stateReferences)
void LocalStore::queryStateReferences(const Path & storePath, PathSet & stateReferences)
{
nix::queryStateReferences(noTxn, storePath, stateReferences);
}
//TODO getStateReferrers....
void queryReferrers(const Transaction & txn,
const Path & storePath, PathSet & referrers)
{
@ -441,6 +460,21 @@ void LocalStore::queryReferrers(const Path & storePath,
}
void queryStateReferrers(const Transaction & txn, const Path & storePath, PathSet & stateReferrers)
{
if (!isRealisablePath(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath);
PathSet stateReferrers2 = getStateReferrers(txn, storePath);
stateReferrers.insert(stateReferrers2.begin(), stateReferrers2.end());
}
void LocalStore::queryStateReferrers(const Path & storePath, PathSet & stateReferrers)
{
nix::queryStateReferrers(noTxn, storePath, stateReferrers);
}
void setDeriver(const Transaction & txn, const Path & storePath, const Path & deriver)
{
assertStorePath(storePath);
@ -498,19 +532,31 @@ bool LocalStore::isStateComponent(const Path & storePath)
return nix::isStateComponentTxn(noTxn, storePath);
}
//TODO Add and ..
bool isStateDrv(const Path & drvPath)
bool isStateDrvPathTxn(const Transaction & txn, const Path & drvPath)
{
Derivation drv = derivationFromPath(drvPath);
return isStateDrvTxn(txn, drv);
}
bool LocalStore::isStateDrvPath(const Path & isStateDrv)
{
return nix::isStateDrvPathTxn(noTxn, isStateDrv);
}
//TODO Add and ..
bool isStateDrvTxn(const Transaction & txn, Derivation drv)
{
Derivation drv = derivationFromPath(drvPath); //maybe redirect the out path to isStateComponent?
if (drv.stateOutputs.size() != 0)
return true;
else
return false;
}
bool LocalStore::isStateDrv(const Path & isStateDrv)
bool LocalStore::isStateDrv(Derivation drv)
{
return nix::isStateDrv(isStateDrv);
return nix::isStateDrvTxn(noTxn, drv);
}
Path queryDeriver(const Transaction & txn, const Path & storePath)
@ -1088,6 +1134,9 @@ void deleteFromStore(const Path & _path, unsigned long long & bytesFreed)
if (*i != path && isValidPathTxn(txn, *i))
throw PathInUse(format("cannot delete path `%1%' because it is in use by path `%2%'") % path % *i);
invalidatePath(txn, path);
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Also delete stateReferrers?????
}
txn.commit();
@ -1178,6 +1227,7 @@ void verifyStore(bool checkContents)
}
}
//TODO also check state references and refererres
/* Check the `references' table. */
printMsg(lvlInfo, "checking the references table");
@ -1245,6 +1295,7 @@ void verifyStore(bool checkContents)
queryReferences(txn, from, references);
PathSet stateReferences;
queryStateReferences(txn, from, stateReferences);
//TODO TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (find(references.begin(), references.end(), to) == references.end()) {
@ -1257,7 +1308,7 @@ void verifyStore(bool checkContents)
}
//TODO Check statecounters table....
//TODO Check stateinfo and statecounters table
txn.commit();

View file

@ -50,6 +50,8 @@ public:
void queryStateReferences(const Path & storePath, PathSet & stateReferences);
void queryReferrers(const Path & path, PathSet & referrers);
void queryStateReferrers(const Path & path, PathSet & stateReferrers);
Path addToStore(const Path & srcPath, bool fixed = false,
bool recursive = false, string hashAlgo = "",
@ -84,7 +86,9 @@ public:
bool isStateComponent(const Path & path);
bool isStateDrv(const Path & drvpath);
bool isStateDrvPath(const Path & drvpath);
bool isStateDrv(Derivation drv);
};
@ -140,7 +144,7 @@ void canonicalisePathMetaData(const Path & path);
/* Checks whether a path is valid. */
bool isValidPathTxn(const Transaction & txn, const Path & path);
/* Sets the set of outgoing FS references for a store path. Use with
/* Sets the set of outgoing FS (also state) references for a store path. Use with
care! */
void setReferences(const Transaction & txn, const Path & path,
const PathSet & references, const PathSet & stateReferences);
@ -190,6 +194,10 @@ void addStateDeriver(const Transaction & txn, const Path & storePath, const Path
PathSet mergeNewDerivationIntoList(const Path & storepath, const Path & newdrv, const PathSet drvs, bool deleteDrvs = false);
bool isStateComponentTxn(const Transaction & txn, const Path & path);
bool isStateDrvPathTxn(const Transaction & txn, const Path & drvPath);
bool isStateDrvTxn(const Transaction & txn, Derivation drv);
}

View file

@ -206,10 +206,8 @@ void RemoteStore::queryStateReferences(const Path & path,
writeInt(wopQueryStateReferences, to);
writeString(path, to);
processStderr();
//TODO TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// PathSet references2 = readStorePaths(from);
// references.insert(references2.begin(), references2.end());
PathSet stateReferences2 = readStorePaths(from);
stateReferences.insert(stateReferences2.begin(), stateReferences2.end());
}
@ -224,6 +222,15 @@ void RemoteStore::queryReferrers(const Path & path,
referrers.insert(referrers2.begin(), referrers2.end());
}
void RemoteStore::queryStateReferrers(const Path & path, PathSet & stateReferrers)
{
writeInt(wopQueryStateReferrers, to);
writeString(path, to);
processStderr();
PathSet stateReferrers2 = readStorePaths(from);
stateReferrers.insert(stateReferrers2.begin(), stateReferrers2.end());
}
Path RemoteStore::addToStore(const Path & _srcPath, bool fixed,
bool recursive, string hashAlgo, PathFilter & filter)
@ -402,15 +409,22 @@ vector<int> RemoteStore::getStatePathsInterval(const PathSet & statePaths)
return intervals;
}
//TODO
bool RemoteStore::isStateComponent(const Path & path)
{
return false;
}
bool RemoteStore::isStateDrv(const Path & drvpath)
//TODO
bool RemoteStore::isStateDrvPath(const Path & drvpath)
{
return false;
return false;
}
//TODO
bool RemoteStore::isStateDrv(Derivation drv)
{
return false;
}
}

View file

@ -38,6 +38,8 @@ public:
void queryStateReferences(const Path & storePath, PathSet & stateReferences);
void queryReferrers(const Path & path, PathSet & referrers);
void queryStateReferrers(const Path & path, PathSet & stateReferrers);
Path addToStore(const Path & srcPath, bool fixed = false,
bool recursive = false, string hashAlgo = "",
@ -72,7 +74,9 @@ public:
bool isStateComponent(const Path & path);
bool isStateDrv(const Path & drvpath);
bool isStateDrvPath(const Path & drvpath);
bool isStateDrv(Derivation drv);
private:

View file

@ -83,6 +83,10 @@ public:
virtual void queryReferrers(const Path & path,
PathSet & referrers) = 0;
/* Queries the set of incoming FS state-references for a store path.
The result is not cleared. */
virtual void queryStateReferrers(const Path & path, PathSet & stateReferrers) = 0;
/* Copy the contents of a path to the store and register the
validity the resulting path. The resulting path is returned.
If `fixed' is true, then the output of a fixed-output
@ -196,7 +200,10 @@ public:
virtual bool isStateComponent(const Path & path) = 0;
/* TODO */
virtual bool isStateDrv(const Path & drvpath) = 0;
virtual bool isStateDrvPath(const Path & drvpath) = 0;
/* TODO */
virtual bool isStateDrv(Derivation drv) = 0;
};