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:
parent
1747d649c5
commit
588356c30a
11 changed files with 158 additions and 154 deletions
|
|
@ -1887,8 +1887,14 @@ void DerivationGoal::computeClosure()
|
|||
for (DerivationOutputs::iterator i = drv.outputs.begin();
|
||||
i != drv.outputs.end(); ++i)
|
||||
{
|
||||
if(isStateDrvPathTxn(txn, drvPath))
|
||||
setStateComponentTxn(txn, i->second.path); //Register the path as a store-state path
|
||||
if(isStateDrv(drv)){ //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CHECK IF THE BUILDER ALSO COMES HERE TWICE WITH A RUNTIME STATEPATH DRV
|
||||
|
||||
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,
|
||||
i->second.path, //component path
|
||||
|
|
|
|||
|
|
@ -492,7 +492,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
|||
if (store->isStateComponent(*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)
|
||||
if (*j != "" && store->isValidPath(*j))
|
||||
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);
|
||||
Path deriver = queryStatePathDrvTxn(noTxn, *i);
|
||||
|
||||
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO put back on
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
assertStorePath(storePath);
|
||||
|
|
@ -708,23 +672,65 @@ void addStateDeriver(const Transaction & txn, const Path & storePath, const Path
|
|||
if (!isValidPathTxn(txn, 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;
|
||||
for (PathSet::iterator i = updatedDerivers.begin(); i != updatedDerivers.end(); ++i) //Convert Paths to Strings
|
||||
data.push_back(*i);
|
||||
nixDB.queryStrings(txn, dbDerivers, storePath, data); //get all current derivers
|
||||
data.push_back(deriver);
|
||||
|
||||
//Remove duplicates
|
||||
data.sort();
|
||||
data.unique();
|
||||
|
||||
//Update
|
||||
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);
|
||||
}
|
||||
|
||||
//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))
|
||||
throw Error(format("path `%1%' is not valid") % storePath);
|
||||
|
||||
if(user == "")
|
||||
throw Error(format("The user argument is empty, use queryDeriver(...) for non-state components"));
|
||||
if(!isStateComponentTxn(txn, storePath))
|
||||
throw Error(format("This path is not a store-state path '%1%'") % storePath);
|
||||
|
||||
Strings alldata;
|
||||
nixDB.queryStrings(txn, dbDerivers, storePath, alldata); //get all current derivers
|
||||
Strings data;
|
||||
PathSet derivers;
|
||||
|
||||
PathSet filtereddata;
|
||||
for (Strings::iterator i = alldata.begin(); i != alldata.end(); ++i) { //filter on username and identifier
|
||||
nixDB.queryStrings(txn, dbDerivers, storePath, data); //get all current derivers
|
||||
for (Strings::iterator i = data.begin(); i != data.end(); ++i)
|
||||
derivers.insert(*i);
|
||||
|
||||
string derivationpath = (*i);
|
||||
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;
|
||||
return derivers;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
|
@ -1055,7 +1038,7 @@ Path LocalStore::addToStore(const Path & _srcPath, bool fixed,
|
|||
canonicalisePathMetaData(dstPath);
|
||||
|
||||
Transaction txn(nixDB);
|
||||
registerValidPath(txn, dstPath, h, PathSet(), PathSet(), "", 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! CHECK (probabyly ok?)
|
||||
registerValidPath(txn, dstPath, h, PathSet(), PathSet(), "", 0);
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
|
@ -1635,45 +1618,47 @@ bool querySolidStateReferencesTxn(const Transaction & txn, const Path & statePat
|
|||
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
|
||||
if(!isValidStatePathTxn(txn, path))
|
||||
throw Error(format("Path `%1%' is not a valid state path") % path);
|
||||
if(!isValidStatePathTxn(txn, statePath))
|
||||
throw Error(format("Path `%1%' is not a valid state path") % statePath);
|
||||
|
||||
//Check if path was shared...
|
||||
Path sharedWithOldPath;
|
||||
if(!querySharedStateTxn(txn, path, sharedWithOldPath))
|
||||
throw Error(format("Path `%1%' is not a shared so cannot be unshared") % path);
|
||||
if(!querySharedStateTxn(txn, statePath, sharedWithOldPath))
|
||||
throw Error(format("Path `%1%' is not a shared so cannot be unshared") % statePath);
|
||||
|
||||
//Remove Symlink
|
||||
removeSymlink(path);
|
||||
removeSymlink(statePath);
|
||||
|
||||
//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
|
||||
Derivation drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, path));
|
||||
ensureStateDir(path, drv.stateOutputs.find("state")->second.username, "nixbld", "700");
|
||||
string user, group;
|
||||
int chmod;
|
||||
getStateUserGroupTxn(txn, statePath, user, group, chmod);
|
||||
ensureStateDir(statePath, user, group, int2String(chmod));
|
||||
|
||||
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
|
||||
if(branch){
|
||||
rsyncPaths(sharedWithOldPath, path, true);
|
||||
rsyncPaths(sharedWithOldPath, statePath, true);
|
||||
}
|
||||
|
||||
//Restore the latest snapshot (non-recursive) made on this statepath
|
||||
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);
|
||||
unShareStateTxn(txn, path, branch, restoreOld);
|
||||
unShareStateTxn(txn, statePath, branch, restoreOld);
|
||||
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
|
||||
Derivation from_drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, from));
|
||||
Derivation to_drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, to));
|
||||
//from
|
||||
//to
|
||||
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
//Snapshot if necessary
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public:
|
|||
|
||||
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);
|
||||
|
||||
|
|
@ -140,6 +140,8 @@ public:
|
|||
|
||||
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
|
||||
files with the same contents. */
|
||||
void optimiseStore(bool dryRun, OptimiseStats & stats);
|
||||
|
|
@ -194,7 +196,7 @@ void setDeriver(const Transaction & txn, const Path & path,
|
|||
const Path & deriver);
|
||||
|
||||
/* 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. */
|
||||
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 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);
|
||||
bool getVersionedStateEntriesTxn(const Transaction & txn, const Path & statePath, StateInfos & infos, const unsigned int revision = 0, const unsigned int timestamp = 0);
|
||||
|
|
|
|||
|
|
@ -451,14 +451,12 @@ void RemoteStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
|||
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);
|
||||
writeString(storePath, to);
|
||||
writeString(identifier, to);
|
||||
writeString(user, to);
|
||||
processStderr();
|
||||
return readStorePaths(from); //TODO is this ok ??
|
||||
return readStorePaths(from);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public:
|
|||
|
||||
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);
|
||||
|
||||
|
|
@ -106,6 +106,8 @@ public:
|
|||
|
||||
void unShareState(const Path & path, const bool branch, const bool restoreOld);
|
||||
|
||||
Path lookupStatePath(const Path & storePath, const string & identifier, const string & user);
|
||||
|
||||
private:
|
||||
AutoCloseFD fdSocket;
|
||||
FdSink to;
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ public:
|
|||
virtual Snapshots commitStatePath(const Path & statePath) = 0;
|
||||
|
||||
/* TODO */
|
||||
virtual PathSet queryDerivers(const Path & storePath, const string & identifier, const string & user) = 0;
|
||||
virtual PathSet queryDerivers(const Path & storePath) = 0;
|
||||
|
||||
/* TODO */
|
||||
virtual void scanAndUpdateAllReferences(const Path & statePath, const bool recursive) = 0;
|
||||
|
|
@ -231,6 +231,9 @@ public:
|
|||
/* TODO */
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ typedef enum {
|
|||
wopRevertToRevision,
|
||||
wopShareState,
|
||||
wopUnShareState,
|
||||
wopSetOptions, //39
|
||||
wopLookupStatePath,
|
||||
wopSetOptions, //40
|
||||
} WorkerOp;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -671,15 +671,8 @@ static void installDerivations(Globals & globals,
|
|||
|
||||
){
|
||||
|
||||
string oldStatePath;
|
||||
//query old state path
|
||||
PathSet derivers = store->queryDerivers(i->queryOutPath(globals.state), newStateIdentifier, queryCurrentUsername()); //TODO Check if username if ok
|
||||
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;
|
||||
Path oldStatePath = store->lookupStatePath(i->queryOutPath(globals.state), newStateIdentifier, queryCurrentUsername());
|
||||
|
||||
//SharePaths
|
||||
printMsg(lvlError, format("Sharing state from old <-- new component '%1%' <-- '%2%'") % oldStatePath % newStatePath);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ void printHelp()
|
|||
//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,
|
||||
bool getDerivers, PathSet & derivers) //optional
|
||||
{
|
||||
|
|
@ -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));
|
||||
|
||||
if(isStateComponent)
|
||||
derivers = store->queryDerivers(componentPath, state_identifier, username); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! needed ???
|
||||
derivers = store->queryDerivers(componentPath);
|
||||
else
|
||||
derivers.insert(store->queryDeriver(componentPath));
|
||||
|
||||
if(getDerivers == true)
|
||||
return Derivation();
|
||||
return;
|
||||
|
||||
if(isStateComponent){
|
||||
if(derivers.size() == 0)
|
||||
|
|
@ -88,18 +88,14 @@ Derivation getDerivation(const string & fullPath, const Strings & program_args,
|
|||
|
||||
//Retrieve the derivation, there is only 1 drvPath in derivers
|
||||
derivationPath = *(derivers.begin());
|
||||
Derivation drv = derivationFromPath(derivationPath);
|
||||
|
||||
if(isStateComponent){
|
||||
DerivationStateOutputs stateOutputs = drv.stateOutputs;
|
||||
statePath = stateOutputs.find("state")->second.statepath;
|
||||
statePath = store->lookupStatePath(componentPath, state_identifier, username);
|
||||
}
|
||||
|
||||
return drv;
|
||||
}
|
||||
|
||||
//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,
|
||||
bool getDerivers, PathSet & derivers) //optional
|
||||
{
|
||||
|
|
@ -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
|
||||
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)
|
||||
{
|
||||
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;
|
||||
bool isStateComponent;
|
||||
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)
|
||||
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;
|
||||
bool isStateComponent;
|
||||
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)
|
||||
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;
|
||||
bool isStateComponent;
|
||||
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;
|
||||
|
||||
|
|
@ -196,7 +192,7 @@ static void queryAvailableStateRevisions(Strings opFlags, Strings opArgs)
|
|||
string derivationPath;
|
||||
bool isStateComponent;
|
||||
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
|
||||
|
|
@ -311,7 +307,7 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
|
|||
string root_derivationPath;
|
||||
bool root_isStateComponent;
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -463,10 +463,8 @@ static void performOp(Source & from, Sink & to, unsigned int op)
|
|||
|
||||
case wopQueryDerivers: {
|
||||
Path path = readStorePath(from);
|
||||
string identifier = readString(from);
|
||||
string user = readString(from);
|
||||
startWork();
|
||||
PathSet derivers = store->queryDerivers(path, identifier, user);
|
||||
PathSet derivers = store->queryDerivers(path);
|
||||
stopWork();
|
||||
writeStringSet(derivers, to);
|
||||
break;
|
||||
|
|
@ -623,6 +621,17 @@ static void performOp(Source & from, Sink & to, unsigned int op)
|
|||
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: {
|
||||
keepFailed = readInt(from) != 0;
|
||||
keepGoing = readInt(from) != 0;
|
||||
|
|
@ -706,7 +715,7 @@ static void processConnection()
|
|||
|
||||
/* Use for debugging with gdb --pid=myPid */
|
||||
if(sleepForGDB)
|
||||
if(oppp == 39){
|
||||
if(oppp == 40){
|
||||
printMsg(lvlError, format("Sleeping 10 before op '%1%' with pid '%2%'") % op % myPid);
|
||||
sleep(10);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue