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

Replaced calls to drvFromPath with database calls.

This commit is contained in:
Wouter den Breejen 2007-10-19 16:43:37 +00:00
parent 1747d649c5
commit 588356c30a
11 changed files with 158 additions and 154 deletions

View file

@ -1887,8 +1887,14 @@ void DerivationGoal::computeClosure()
for (DerivationOutputs::iterator i = drv.outputs.begin(); for (DerivationOutputs::iterator i = drv.outputs.begin();
i != drv.outputs.end(); ++i) i != drv.outputs.end(); ++i)
{ {
if(isStateDrvPathTxn(txn, drvPath)) if(isStateDrv(drv)){ //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CHECK IF THE BUILDER ALSO COMES HERE TWICE WITH A RUNTIME STATEPATH DRV
setStateComponentTxn(txn, i->second.path); //Register the path as a store-state path
Path statePath = drv.stateOutputs.find("state")->second.statepath;
string identifier = drv.stateOutputs.find("state")->second.stateIdentifier;
string user = drv.stateOutputs.find("state")->second.username;
setStateComponentTxn(txn, i->second.path, statePath, identifier , user); //Register the path as a store-state path
}
registerValidPath(txn, registerValidPath(txn,
i->second.path, //component path i->second.path, //component path

View file

@ -492,7 +492,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
if (store->isStateComponent(*i)){ if (store->isStateComponent(*i)){
//printMsg(lvlError, format("Live state store '%1%'") % *i); //printMsg(lvlError, format("Live state store '%1%'") % *i);
PathSet derivers = store->queryDerivers(*i, "*", "*"); //we select ALL state Derivations here //TODO ??? we shouldt select non live !!!!!!!!! PathSet derivers = store->queryDerivers(*i); //we select ALL state Derivations here
for (PathSet::const_iterator j = derivers.begin(); j != derivers.end(); ++j) for (PathSet::const_iterator j = derivers.begin(); j != derivers.end(); ++j)
if (*j != "" && store->isValidPath(*j)) if (*j != "" && store->isValidPath(*j))
computeFSClosure(*j, livePaths, true, true, 0); computeFSClosure(*j, livePaths, true, true, 0);
@ -508,9 +508,8 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
//printMsg(lvlError, format("Live State '%1%'") % *i); //printMsg(lvlError, format("Live State '%1%'") % *i);
Path deriver = queryStatePathDrvTxn(noTxn, *i); Path deriver = queryStatePathDrvTxn(noTxn, *i);
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO put back on
if(!store->isValidPath(deriver)) if(!store->isValidPath(deriver))
{} // throw Error(format("deriver `%1%' of state-store component `%2%' in GC is not valid") % deriver % *i); throw Error(format("deriver `%1%' of state-store component `%2%' in GC is not valid") % deriver % *i);
computeFSClosure(deriver, livePaths, true, true, 0); computeFSClosure(deriver, livePaths, true, true, 0);
} }

View file

@ -662,42 +662,6 @@ void setDeriver(const Transaction & txn, const Path & storePath, const Path & de
} }
} }
/* Private function only used by addStateDeriver
* Merges a new derivation into a list of derivations, this function takes username and statepath
* into account. This function is used to update derivations that have only changed for example in their sub state
* paths that need to be versioned. We assume newdrv is the newest.
*/
PathSet mergeNewDerivationIntoListTxn(const Transaction & txn, const Path & storepath, const Path & newdrv, const PathSet drvs, bool deleteDrvs)
{
PathSet newdrvs;
Derivation drv = derivationFromPathTxn(txn, newdrv);
string identifier = drv.stateOutputs.find("state")->second.stateIdentifier;
string user = drv.stateOutputs.find("state")->second.username;
for (PathSet::iterator i = drvs.begin(); i != drvs.end(); ++i) //Check if we need to remove old drvs
{
Path drv = *i;
Derivation getdrv = derivationFromPathTxn(txn, drv);
string getIdentifier = getdrv.stateOutputs.find("state")->second.stateIdentifier;
string getUser = getdrv.stateOutputs.find("state")->second.username;
if(identifier == getIdentifier && getUser == user) //only insert if it doenst already exist
{
//We also check if it's NOT exactly the same drvpath
if(drv != newdrv && deleteDrvs){
printMsg(lvlTalkative, format("Deleting decrepated state derivation: %1% with identifier %2% and user %3%") % drv % identifier % user);
deletePath(drv); //Deletes the DRV from DISK!
}
}
else
newdrvs.insert(drv);
}
newdrvs.insert(newdrv);
return newdrvs;
}
void addStateDeriver(const Transaction & txn, const Path & storePath, const Path & deriver) void addStateDeriver(const Transaction & txn, const Path & storePath, const Path & deriver)
{ {
assertStorePath(storePath); assertStorePath(storePath);
@ -708,23 +672,65 @@ void addStateDeriver(const Transaction & txn, const Path & storePath, const Path
if (!isValidPathTxn(txn, storePath)) if (!isValidPathTxn(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath); throw Error(format("path `%1%' is not valid") % storePath);
Derivation drv = derivationFromPathTxn(txn, deriver);
string identifier = drv.stateOutputs.find("state")->second.stateIdentifier;
string user = drv.stateOutputs.find("state")->second.username;
PathSet currentDerivers = queryDerivers(txn, storePath, identifier, user);
PathSet updatedDerivers = mergeNewDerivationIntoListTxn(txn, storePath, deriver, currentDerivers, true);
Strings data; Strings data;
for (PathSet::iterator i = updatedDerivers.begin(); i != updatedDerivers.end(); ++i) //Convert Paths to Strings nixDB.queryStrings(txn, dbDerivers, storePath, data); //get all current derivers
data.push_back(*i); data.push_back(deriver);
//Remove duplicates
data.sort();
data.unique();
//Update
nixDB.setStrings(txn, dbDerivers, storePath, data); //update the derivers db. nixDB.setStrings(txn, dbDerivers, storePath, data); //update the derivers db.
} }
void setStateComponentTxn(const Transaction & txn, const Path & storePath) void setStateComponentTxn(const Transaction & txn, const Path & storePath,
const Path & statePath, const string & identifier, const string & user)
{ {
nixDB.setString(txn, dbStateInfo, storePath, ""); //update the dbinfo db. (maybe TODO) string key = mergeToDBKey(statePath, mergeToDBKey(identifier, user));
Strings data;
nixDB.queryStrings(txn, dbStateInfo, storePath, data);
for (Strings::iterator i = data.begin(); i != data.end(); ++i){
string t1, getUser, getStatePath, getIdentifier;
splitDBKey(*i, t1, getUser);
splitDBKey(t1, getStatePath, getIdentifier);
if(getUser == user && getIdentifier == identifier)
if(getStatePath == statePath)
return;
else
throw Error(format("Trying to insert duplicate state paths '%1%' and '%2%' for storepath '%3%'") % getStatePath % statePath % storePath);
}
data.push_back(key);
nixDB.setStrings(txn, dbStateInfo, storePath, data); //update the dbinfo db. (maybe TODO)
}
Path lookupStatePathTxn(const Transaction & txn, const Path & storePath,
const string & identifier, const string & user)
{
if (!isValidPathTxn(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath);
Strings data;
nixDB.queryStrings(txn, dbStateInfo, storePath, data);
for (Strings::iterator i = data.begin(); i != data.end(); ++i){
string t1, getUser, getStatePath, getIdentifier;
splitDBKey(*i, t1, getUser);
splitDBKey(t1, getStatePath, getIdentifier);
if(getUser == user && getIdentifier == identifier)
return getStatePath;
}
throw Error(format("No statePath found for '%1%' with user '%2%' and identifier '%3%'") % storePath % identifier % user);
}
Path LocalStore::lookupStatePath(const Path & storePath, const string & identifier, const string & user)
{
return lookupStatePathTxn(noTxn, storePath, identifier, user);
} }
/* /*
@ -788,56 +794,33 @@ Path LocalStore::queryDeriver(const Path & path)
return nix::queryDeriver(noTxn, path); return nix::queryDeriver(noTxn, path);
} }
//A '*' as argument stands for all identifiers or all users
PathSet queryDerivers(const Transaction & txn, const Path & storePath, const string & identifier, const string & user) /*
* WARNING: Derivers might have been deleted by the GC and still be in this list !!
*/
PathSet queryDerivers(const Transaction & txn, const Path & storePath)
{ {
if (!isValidPathTxn(txn, storePath)) if (!isValidPathTxn(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath); throw Error(format("path `%1%' is not valid") % storePath);
if(user == "") if(!isStateComponentTxn(txn, storePath))
throw Error(format("The user argument is empty, use queryDeriver(...) for non-state components")); throw Error(format("This path is not a store-state path '%1%'") % storePath);
Strings alldata; Strings data;
nixDB.queryStrings(txn, dbDerivers, storePath, alldata); //get all current derivers PathSet derivers;
PathSet filtereddata; nixDB.queryStrings(txn, dbDerivers, storePath, data); //get all current derivers
for (Strings::iterator i = alldata.begin(); i != alldata.end(); ++i) { //filter on username and identifier for (Strings::iterator i = data.begin(); i != data.end(); ++i)
derivers.insert(*i);
string derivationpath = (*i); return derivers;
Derivation drv = derivationFromPathTxn(txn, derivationpath);
if (drv.outputs.size() != 1)
throw Error(format("The call queryDerivers with storepath %1% is not a statePath") % storePath);
string getIdentifier = drv.stateOutputs.find("state")->second.stateIdentifier;
string getUser = drv.stateOutputs.find("state")->second.username;
//printMsg(lvlError, format("queryDerivers '%1%' '%2%' '%3%' '%4%' '%5%'") % derivationpath % getIdentifier % identifier % getUser % user);
if( (getIdentifier == identifier || identifier == "*") && (getUser == user || user == "*") )
filtereddata.insert(derivationpath);
}
return filtereddata;
} }
PathSet LocalStore::queryDerivers(const Path & storePath, const string & identifier, const string & user) PathSet LocalStore::queryDerivers(const Path & storePath)
{ {
return nix::queryDerivers(noTxn, storePath, identifier, user); return nix::queryDerivers(noTxn, storePath);
} }
//Wrapper around converting the drvPath to the statePath
/*
PathSet queryDeriversStatePath(const Transaction & txn, const Path & storePath, const string & identifier, const string & user)
{
PathSet drvs = queryDerivers(txn, storePath, identifier, user);
PathSet statePaths;
for (PathSet::const_iterator i = drvs.begin(); i != drvs.end(); i++){
Derivation drv = derivationFromPath((*i));
statePaths.insert(drv.stateOutputs.find("state")->second.statepath);
}
return statePaths;
}
*/
PathSet LocalStore::querySubstitutablePaths() PathSet LocalStore::querySubstitutablePaths()
{ {
@ -1055,7 +1038,7 @@ Path LocalStore::addToStore(const Path & _srcPath, bool fixed,
canonicalisePathMetaData(dstPath); canonicalisePathMetaData(dstPath);
Transaction txn(nixDB); Transaction txn(nixDB);
registerValidPath(txn, dstPath, h, PathSet(), PathSet(), "", 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! CHECK (probabyly ok?) registerValidPath(txn, dstPath, h, PathSet(), PathSet(), "", 0);
txn.commit(); txn.commit();
} }
@ -1635,45 +1618,47 @@ bool querySolidStateReferencesTxn(const Transaction & txn, const Path & statePat
return notempty; return notempty;
} }
void unShareStateTxn(const Transaction & txn, const Path & path, const bool branch, const bool restoreOld) void unShareStateTxn(const Transaction & txn, const Path & statePath, const bool branch, const bool restoreOld)
{ {
//Check if is statePath //Check if is statePath
if(!isValidStatePathTxn(txn, path)) if(!isValidStatePathTxn(txn, statePath))
throw Error(format("Path `%1%' is not a valid state path") % path); throw Error(format("Path `%1%' is not a valid state path") % statePath);
//Check if path was shared... //Check if path was shared...
Path sharedWithOldPath; Path sharedWithOldPath;
if(!querySharedStateTxn(txn, path, sharedWithOldPath)) if(!querySharedStateTxn(txn, statePath, sharedWithOldPath))
throw Error(format("Path `%1%' is not a shared so cannot be unshared") % path); throw Error(format("Path `%1%' is not a shared so cannot be unshared") % statePath);
//Remove Symlink //Remove Symlink
removeSymlink(path); removeSymlink(statePath);
//Remove earlier entries (unshare) (we must do this before revertToRevisionTxn) //Remove earlier entries (unshare) (we must do this before revertToRevisionTxn)
nixDB.delPair(txn, dbSharedState, path); nixDB.delPair(txn, dbSharedState, statePath);
//Touch dir with correct rights //Touch dir with correct rights
Derivation drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, path)); string user, group;
ensureStateDir(path, drv.stateOutputs.find("state")->second.username, "nixbld", "700"); int chmod;
getStateUserGroupTxn(txn, statePath, user, group, chmod);
ensureStateDir(statePath, user, group, int2String(chmod));
if(branch && restoreOld) if(branch && restoreOld)
throw Error(format("You cannot branch and restore the old state at the same time for path: '%1%' ") % path); throw Error(format("You cannot branch and restore the old state at the same time for path: '%1%' ") % statePath);
//Copy if necessary //Copy if necessary
if(branch){ if(branch){
rsyncPaths(sharedWithOldPath, path, true); rsyncPaths(sharedWithOldPath, statePath, true);
} }
//Restore the latest snapshot (non-recursive) made on this statepath //Restore the latest snapshot (non-recursive) made on this statepath
if(restoreOld){ if(restoreOld){
revertToRevisionTxn(txn, path, 0, false); revertToRevisionTxn(txn, statePath, 0, false);
} }
} }
void LocalStore::unShareState(const Path & path, const bool branch, const bool restoreOld) void LocalStore::unShareState(const Path & statePath, const bool branch, const bool restoreOld)
{ {
Transaction txn(nixDB); Transaction txn(nixDB);
unShareStateTxn(txn, path, branch, restoreOld); unShareStateTxn(txn, statePath, branch, restoreOld);
txn.commit(); txn.commit();
} }
@ -1699,8 +1684,8 @@ void shareStateTxn(const Transaction & txn, const Path & from, const Path & to,
} }
//Check if the user has the right to share this path //Check if the user has the right to share this path
Derivation from_drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, from)); //from
Derivation to_drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, to)); //to
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Snapshot if necessary //Snapshot if necessary

View file

@ -126,7 +126,7 @@ public:
Snapshots commitStatePath(const Path & statePath); Snapshots commitStatePath(const Path & statePath);
PathSet queryDerivers(const Path & storePath, const string & identifier, const string & user); //should these be in here ???? PathSet queryDerivers(const Path & storePath); //should these be in here ????
void scanAndUpdateAllReferences(const Path & statePath, const bool recursive); void scanAndUpdateAllReferences(const Path & statePath, const bool recursive);
@ -140,6 +140,8 @@ public:
void unShareState(const Path & path, const bool branch, const bool restoreOld); void unShareState(const Path & path, const bool branch, const bool restoreOld);
Path lookupStatePath(const Path & storePath, const string & identifier, const string & user);
/* Optimise the disk space usage of the Nix store by hard-linking /* Optimise the disk space usage of the Nix store by hard-linking
files with the same contents. */ files with the same contents. */
void optimiseStore(bool dryRun, OptimiseStats & stats); void optimiseStore(bool dryRun, OptimiseStats & stats);
@ -194,7 +196,7 @@ void setDeriver(const Transaction & txn, const Path & path,
const Path & deriver); const Path & deriver);
/* Query the derivers of a state-store path. */ /* Query the derivers of a state-store path. */
PathSet queryDerivers(const Transaction & txn, const Path & storePath, const string & identifier, const string & user); PathSet queryDerivers(const Transaction & txn, const Path & storePath);
/* Delete a value from the nixStore directory. */ /* Delete a value from the nixStore directory. */
void deleteFromStore(const Path & path, unsigned long long & bytesFreed); void deleteFromStore(const Path & path, unsigned long long & bytesFreed);
@ -274,7 +276,7 @@ void setStatePathsIntervalTxn(const Transaction & txn, const Path & statePath, c
bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision); bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision);
bool querySharedStateTxn(const Transaction & txn, const Path & statePath, Path & shared_with); bool querySharedStateTxn(const Transaction & txn, const Path & statePath, Path & shared_with);
void setStateComponentTxn(const Transaction & txn, const Path & storePath); void setStateComponentTxn(const Transaction & txn, const Path & storePath, const Path & statePath, const string & identifier, const string & user);
void setVersionedStateEntriesTxn(const Transaction & txn, const Path & statePath, const StateInfos & infos, const unsigned int revision = 0, const unsigned int timestamp = 0); void setVersionedStateEntriesTxn(const Transaction & txn, const Path & statePath, const StateInfos & infos, const unsigned int revision = 0, const unsigned int timestamp = 0);
bool getVersionedStateEntriesTxn(const Transaction & txn, const Path & statePath, StateInfos & infos, const unsigned int revision = 0, const unsigned int timestamp = 0); bool getVersionedStateEntriesTxn(const Transaction & txn, const Path & statePath, StateInfos & infos, const unsigned int revision = 0, const unsigned int timestamp = 0);

View file

@ -451,14 +451,12 @@ void RemoteStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
bytesFreed = (((unsigned long long) hi) << 32) | lo; bytesFreed = (((unsigned long long) hi) << 32) | lo;
} }
PathSet RemoteStore::queryDerivers(const Path & storePath, const string & identifier, const string & user) PathSet RemoteStore::queryDerivers(const Path & storePath)
{ {
writeInt(wopQueryDerivers, to); writeInt(wopQueryDerivers, to);
writeString(storePath, to); writeString(storePath, to);
writeString(identifier, to);
writeString(user, to);
processStderr(); processStderr();
return readStorePaths(from); //TODO is this ok ?? return readStorePaths(from);
} }
void RemoteStore::setStatePathsInterval(const Path & statePath, const CommitIntervals & intervals) void RemoteStore::setStatePathsInterval(const Path & statePath, const CommitIntervals & intervals)
@ -600,6 +598,16 @@ void RemoteStore::unShareState(const Path & path, const bool branch, const bool
readInt(from); readInt(from);
} }
Path RemoteStore::lookupStatePath(const Path & storePath, const string & identifier, const string & user)
{
writeInt(wopLookupStatePath, to);
writeString(storePath, to);
writeString(identifier, to);
writeString(user, to);
processStderr();
return readStatePath(from);
}
void RemoteStore::processStderr(Sink * sink, Source * source) void RemoteStore::processStderr(Sink * sink, Source * source)
{ {

View file

@ -92,7 +92,7 @@ public:
Snapshots commitStatePath(const Path & statePath); Snapshots commitStatePath(const Path & statePath);
PathSet queryDerivers(const Path & storePath, const string & identifier, const string & user); PathSet queryDerivers(const Path & storePath);
void scanAndUpdateAllReferences(const Path & statePath, const bool recursive); void scanAndUpdateAllReferences(const Path & statePath, const bool recursive);
@ -106,6 +106,8 @@ public:
void unShareState(const Path & path, const bool branch, const bool restoreOld); void unShareState(const Path & path, const bool branch, const bool restoreOld);
Path lookupStatePath(const Path & storePath, const string & identifier, const string & user);
private: private:
AutoCloseFD fdSocket; AutoCloseFD fdSocket;
FdSink to; FdSink to;

View file

@ -211,7 +211,7 @@ public:
virtual Snapshots commitStatePath(const Path & statePath) = 0; virtual Snapshots commitStatePath(const Path & statePath) = 0;
/* TODO */ /* TODO */
virtual PathSet queryDerivers(const Path & storePath, const string & identifier, const string & user) = 0; virtual PathSet queryDerivers(const Path & storePath) = 0;
/* TODO */ /* TODO */
virtual void scanAndUpdateAllReferences(const Path & statePath, const bool recursive) = 0; virtual void scanAndUpdateAllReferences(const Path & statePath, const bool recursive) = 0;
@ -231,6 +231,9 @@ public:
/* TODO */ /* TODO */
virtual void unShareState(const Path & path, const bool branch, const bool restoreOld) = 0; virtual void unShareState(const Path & path, const bool branch, const bool restoreOld) = 0;
/* TODO */
virtual Path lookupStatePath(const Path & storePath, const string & identifier, const string & user) = 0;
}; };

View file

@ -51,7 +51,8 @@ typedef enum {
wopRevertToRevision, wopRevertToRevision,
wopShareState, wopShareState,
wopUnShareState, wopUnShareState,
wopSetOptions, //39 wopLookupStatePath,
wopSetOptions, //40
} WorkerOp; } WorkerOp;

View file

@ -671,15 +671,8 @@ static void installDerivations(Globals & globals,
){ ){
string oldStatePath;
//query old state path //query old state path
PathSet derivers = store->queryDerivers(i->queryOutPath(globals.state), newStateIdentifier, queryCurrentUsername()); //TODO Check if username if ok Path oldStatePath = store->lookupStatePath(i->queryOutPath(globals.state), newStateIdentifier, queryCurrentUsername());
if(derivers.size() != 1)
throw Error(format("Internal Error: There is not exactly one deriver with state_identifier '%1%' for path '%2%'")
% newStateIdentifier % i->queryOutPath(globals.state));
Path oldDrvPath = *(derivers.begin());
Derivation oldDrv = derivationFromPath(oldDrvPath);
oldStatePath = oldDrv.stateOutputs.find("state")->second.statepath;
//SharePaths //SharePaths
printMsg(lvlError, format("Sharing state from old <-- new component '%1%' <-- '%2%'") % oldStatePath % newStatePath); printMsg(lvlError, format("Sharing state from old <-- new component '%1%' <-- '%2%'") % oldStatePath % newStatePath);

View file

@ -53,9 +53,9 @@ void printHelp()
//cout << string((char *) helpText, sizeof helpText); //cout << string((char *) helpText, sizeof helpText);
} }
Derivation getDerivation(const string & fullPath, const Strings & program_args, string state_identifier, Path & componentPath, Path & statePath, void getPathInfo(const string & fullPath, const Strings & program_args, string state_identifier, Path & componentPath, Path & statePath,
string & binary, string & derivationPath, bool isStateComponent, string & binary, string & derivationPath, bool isStateComponent,
bool getDerivers, PathSet & derivers) //optional bool getDerivers, PathSet & derivers) //optional
{ {
//Parse the full path like /nix/store/...../bin/hello //Parse the full path like /nix/store/...../bin/hello
componentPath = fullPath.substr(nixStore.size() + 1, fullPath.size()); //+1 to strip off the / componentPath = fullPath.substr(nixStore.size() + 1, fullPath.size()); //+1 to strip off the /
@ -72,12 +72,12 @@ Derivation getDerivation(const string & fullPath, const Strings & program_args,
//printMsg(lvlError, format("'%1%' - '%2%' - '%3%' - '%4%' - '%5%'") % componentPath % state_identifier % binary % username % bool2string(isStateComponent)); //printMsg(lvlError, format("'%1%' - '%2%' - '%3%' - '%4%' - '%5%'") % componentPath % state_identifier % binary % username % bool2string(isStateComponent));
if(isStateComponent) if(isStateComponent)
derivers = store->queryDerivers(componentPath, state_identifier, username); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! needed ??? derivers = store->queryDerivers(componentPath);
else else
derivers.insert(store->queryDeriver(componentPath)); derivers.insert(store->queryDeriver(componentPath));
if(getDerivers == true) if(getDerivers == true)
return Derivation(); return;
if(isStateComponent){ if(isStateComponent){
if(derivers.size() == 0) if(derivers.size() == 0)
@ -88,20 +88,16 @@ Derivation getDerivation(const string & fullPath, const Strings & program_args,
//Retrieve the derivation, there is only 1 drvPath in derivers //Retrieve the derivation, there is only 1 drvPath in derivers
derivationPath = *(derivers.begin()); derivationPath = *(derivers.begin());
Derivation drv = derivationFromPath(derivationPath);
if(isStateComponent){ if(isStateComponent){
DerivationStateOutputs stateOutputs = drv.stateOutputs; statePath = store->lookupStatePath(componentPath, state_identifier, username);
statePath = stateOutputs.find("state")->second.statepath;
} }
return drv;
} }
//Wrapper //Wrapper
Derivation getDerivation_andCheckArgs_(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath, void getPathInfo_andCheckArgs_(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath,
string & binary, string & derivationPath, bool isStateComponent, Strings & program_args, string & binary, string & derivationPath, bool isStateComponent, Strings & program_args,
bool getDerivers, PathSet & derivers) //optional bool getDerivers, PathSet & derivers) //optional
{ {
if (!opFlags.empty()) throw UsageError("unknown flag"); if (!opFlags.empty()) throw UsageError("unknown flag");
if ( opArgs.size() < 1) if ( opArgs.size() < 1)
@ -119,15 +115,15 @@ Derivation getDerivation_andCheckArgs_(Strings opFlags, Strings opArgs, Path & c
} }
} }
return getDerivation(fullPath, program_args, stateIdentifier, componentPath, statePath, binary, derivationPath, isStateComponent, getDerivers, derivers); getPathInfo(fullPath, program_args, stateIdentifier, componentPath, statePath, binary, derivationPath, isStateComponent, getDerivers, derivers);
} }
//Wrapper //Wrapper
Derivation getDerivation_andCheckArgs(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath, void getPathInfo_andCheckArgs(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath,
string & binary, string & derivationPath, bool & isStateComponent, Strings & program_args) string & binary, string & derivationPath, bool & isStateComponent, Strings & program_args)
{ {
PathSet empty; PathSet empty;
return getDerivation_andCheckArgs_(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args, false, empty); getPathInfo_andCheckArgs_(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args, false, empty);
} }
// //
@ -140,7 +136,7 @@ static void opShowDerivations(Strings opFlags, Strings opArgs)
string derivationPath; string derivationPath;
bool isStateComponent; bool isStateComponent;
Strings program_args; Strings program_args;
Derivation drv = getDerivation_andCheckArgs_(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args, true, derivers); getPathInfo_andCheckArgs_(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args, true, derivers);
if(!isStateComponent) if(!isStateComponent)
throw UsageError(format("This path '%1%' is not a state-component path") % componentPath); throw UsageError(format("This path '%1%' is not a state-component path") % componentPath);
@ -159,7 +155,7 @@ static void opShowStatePath(Strings opFlags, Strings opArgs)
string derivationPath; string derivationPath;
bool isStateComponent; bool isStateComponent;
Strings program_args; Strings program_args;
Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args); getPathInfo_andCheckArgs(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args);
if(!isStateComponent) if(!isStateComponent)
throw UsageError(format("This path '%1%' is not a state-component path") % componentPath); throw UsageError(format("This path '%1%' is not a state-component path") % componentPath);
@ -176,7 +172,7 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
string derivationPath; string derivationPath;
bool isStateComponent; bool isStateComponent;
Strings program_args; Strings program_args;
Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args); getPathInfo_andCheckArgs(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args);
bool recursive = revert_recursively; bool recursive = revert_recursively;
@ -196,7 +192,7 @@ static void queryAvailableStateRevisions(Strings opFlags, Strings opArgs)
string derivationPath; string derivationPath;
bool isStateComponent; bool isStateComponent;
Strings program_args; Strings program_args;
Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args); getPathInfo_andCheckArgs(opFlags, opArgs, componentPath, statePath, binary, derivationPath, isStateComponent, program_args);
} }
//Lookup unshared path if neccacary //Lookup unshared path if neccacary
@ -311,7 +307,7 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
string root_derivationPath; string root_derivationPath;
bool root_isStateComponent; bool root_isStateComponent;
Strings root_program_args; Strings root_program_args;
Derivation root_drv = getDerivation_andCheckArgs(opFlags, opArgs, root_componentPath, root_statePath, root_binary, root_derivationPath, root_isStateComponent, root_program_args); getPathInfo_andCheckArgs(opFlags, opArgs, root_componentPath, root_statePath, root_binary, root_derivationPath, root_isStateComponent, root_program_args);
//printMsg(lvlError, format("compp: '%1%'\nstatep: '%2%'\nbinary: '%3%'\ndrv:'%4%'") % root_componentPath % root_statePath % root_binary % root_derivationPath); //printMsg(lvlError, format("compp: '%1%'\nstatep: '%2%'\nbinary: '%3%'\ndrv:'%4%'") % root_componentPath % root_statePath % root_binary % root_derivationPath);

View file

@ -463,10 +463,8 @@ static void performOp(Source & from, Sink & to, unsigned int op)
case wopQueryDerivers: { case wopQueryDerivers: {
Path path = readStorePath(from); Path path = readStorePath(from);
string identifier = readString(from);
string user = readString(from);
startWork(); startWork();
PathSet derivers = store->queryDerivers(path, identifier, user); PathSet derivers = store->queryDerivers(path);
stopWork(); stopWork();
writeStringSet(derivers, to); writeStringSet(derivers, to);
break; break;
@ -623,6 +621,17 @@ static void performOp(Source & from, Sink & to, unsigned int op)
break; break;
} }
case wopLookupStatePath: {
Path storePath = readStorePath(from);
string identifier = readString(from);
string user = readString(from);
startWork();
Path statePath = store->lookupStatePath(storePath, identifier, user);
stopWork();
writeString(statePath, to);
break;
}
case wopSetOptions: { case wopSetOptions: {
keepFailed = readInt(from) != 0; keepFailed = readInt(from) != 0;
keepGoing = readInt(from) != 0; keepGoing = readInt(from) != 0;
@ -706,7 +715,7 @@ static void processConnection()
/* Use for debugging with gdb --pid=myPid */ /* Use for debugging with gdb --pid=myPid */
if(sleepForGDB) if(sleepForGDB)
if(oppp == 39){ if(oppp == 40){
printMsg(lvlError, format("Sleeping 10 before op '%1%' with pid '%2%'") % op % myPid); printMsg(lvlError, format("Sleeping 10 before op '%1%' with pid '%2%'") % op % myPid);
sleep(10); sleep(10);
} }