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

downscaled to 1 repos per statePath

This commit is contained in:
Wouter den Breejen 2007-07-08 22:40:16 +00:00
parent cce4156232
commit 9f00b42f38
19 changed files with 218 additions and 399 deletions

View file

@ -1200,7 +1200,7 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook()
*probably* already has it.) */
PathSet allInputs;
allInputs.insert(inputPaths.begin(), inputPaths.end());
computeFSClosure(drvPath, allInputs, true, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE
computeFSClosure(drvPath, allInputs, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE
string s;
for (PathSet::iterator i = allInputs.begin();
@ -1323,8 +1323,8 @@ bool DerivationGoal::prepareBuild()
Derivation inDrv = derivationFromPath(i->first);
for (StringSet::iterator j = i->second.begin(); j != i->second.end(); ++j)
if (inDrv.outputs.find(*j) != inDrv.outputs.end()){
computeFSClosure(inDrv.outputs[*j].path, inputPaths, true, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE (done?)
computeFSClosure(inDrv.outputs[*j].path, inputStatePaths, false, true); //TODO!!!!!!!!!!!!! HOW CAN THESE PATHS ALREADY BE VALID ..... ?????????????????????
computeFSClosure(inDrv.outputs[*j].path, inputPaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE (done?)
computeFSClosure(inDrv.outputs[*j].path, inputStatePaths, false, true, -1); //TODO!!!!!!!!!!!!! HOW CAN THESE PATHS ALREADY BE VALID ..... ?????????????????????
}
else
throw BuildError(
@ -1334,8 +1334,8 @@ bool DerivationGoal::prepareBuild()
/* Second, the input sources. */
for (PathSet::iterator i = drv.inputSrcs.begin(); i != drv.inputSrcs.end(); ++i){
computeFSClosure(*i, inputPaths, true, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE (done?)
computeFSClosure(*i, inputStatePaths, false, true);
computeFSClosure(*i, inputPaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE (done?)
computeFSClosure(*i, inputStatePaths, false, true, -1);
}
debug(format("added input paths %1%") % showPaths(inputPaths));
@ -1463,7 +1463,7 @@ void DerivationGoal::startBuilder()
/* Write closure info to `fileName'. */
PathSet refs;
computeFSClosure(storePath, refs, true, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE
computeFSClosure(storePath, refs, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE
/* !!! in secure Nix, the writing should be done on the
build uid for security (maybe). */
writeStringToFile(tmpDir + "/" + fileName,

View file

@ -555,40 +555,6 @@ bool Database::queryStateReferences(const Transaction & txn, TableId table,
else
key = makeStatePathRevision(statePath, revision);
/*
///////////////?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! create function
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TODO
string key = ""; //final key that matches revision + statePath
int highestRev = -1;
//Lookup which key we need
for (Strings::iterator i = keys.begin(); i != keys.end(); ++i) {
Path getStatePath_org = *i;
Path getStatePath;
int getRevision;
splitStatePathRevision(*i, getStatePath, getRevision);
if(getStatePath == statePath){
if(revision == -1){ //the user wants the last revision
if(getRevision > highestRev)
highestRev = getRevision;
}
else if(revision == getRevision){
key = getStatePath_org;
break;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(key == "" && highestRev == -1) //no records found (TODO throw error?)
return false;
if(revision == -1)
key = makeStatePathRevision(statePath, highestRev);
*/
return queryStrings(txn, table, key, references); //now that we have the key, we can query the references
}
@ -610,15 +576,15 @@ bool Database::queryStateReferrers(const Transaction & txn, TableId table,
void Database::setStateRevisions(const Transaction & txn, TableId table,
const Path & statePath, const RevisionNumbersSetClosure & revisions, int revision)
const Path & statePath, const RevisionNumbersSet & revisions, int revision)
{
if(revision == -1)
revision = getNewRevisionNumber(txn, table, statePath);
//Sort based on statePath to RevisionNumbersClosure
RevisionNumbersClosure sorted_revisions;
RevisionNumbers sorted_revisions;
vector<Path> sortedStatePaths;
for (RevisionNumbersSetClosure::const_iterator i = revisions.begin(); i != revisions.end(); ++i)
for (RevisionNumbersSet::const_iterator i = revisions.begin(); i != revisions.end(); ++i)
sortedStatePaths.push_back((*i).first);
sort(sortedStatePaths.begin(), sortedStatePaths.end());
for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i)
@ -626,22 +592,16 @@ void Database::setStateRevisions(const Transaction & txn, TableId table,
//////////////////
for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i){
printMsg(lvlError, format("Insert: %1%") % *i);
for (RevisionNumbers::const_iterator e = (revisions.at(*i)).begin(); e != (revisions.at(*i)).end(); ++e)
printMsg(lvlError, format("Rev: %1%") % *e);
printMsg(lvlError, format("Insert: %1% into %2%") % int2String(revisions.at(*i)) % *i);
}
//////////////////
//Pack the data into Strings
const string seperator = "|";
Strings data;
for (RevisionNumbersClosure::const_iterator i = sorted_revisions.begin(); i != sorted_revisions.end(); ++i) {
RevisionNumbers revisionNumbers = *i;
string packedNumbers = "";
for (RevisionNumbers::iterator j = revisionNumbers.begin(); j != revisionNumbers.end(); ++j)
packedNumbers += int2String(*j) + seperator;
packedNumbers = packedNumbers.substr(0, packedNumbers.length()-1); //remove the last |
data.push_back(packedNumbers);
//Convert the int's into Strings
Strings data;
for (RevisionNumbers::const_iterator i = sorted_revisions.begin(); i != sorted_revisions.end(); ++i) {
int revisionnumber = *i;
data.push_back(int2String(revisionnumber));
}
//Create the key
@ -652,10 +612,8 @@ void Database::setStateRevisions(const Transaction & txn, TableId table,
}
bool Database::queryStateRevisions(const Transaction & txn, TableId table,
const Path & statePath, RevisionNumbersClosure & revisions, int revision)
const Path & statePath, RevisionNumbers & revisions, int revision)
{
const string seperator = "|";
Strings keys;
enumTable(txn, table, keys); //get all revisions
@ -668,55 +626,17 @@ bool Database::queryStateRevisions(const Transaction & txn, TableId table,
else
key = makeStatePathRevision(statePath, revision);
/*
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string key = ""; //final key that matches revision + statePath
int highestRev = -1;
//Lookup which key we need
for (Strings::iterator i = keys.begin(); i != keys.end(); ++i) {
Path getStatePath_org = *i;
Path getStatePath;
int getRevision;
splitStatePathRevision(*i, getStatePath, getRevision);
if(getStatePath == statePath){
if(revision == -1){ //the user wants the last revision
if(getRevision > highestRev)
highestRev = getRevision;
}
else if(revision == getRevision){
key = getStatePath_org;
break;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(key == "" && highestRev == -1) //no records found (TODO throw error?)
return false;
if(revision == -1)
key = makeStatePathRevision(statePath, highestRev);
*/
Strings data;
bool succeed = queryStrings(txn, table, key, data); //now that we have the key, we can query the references
//Unpack Strings into RevisionNumbersClosure
//Convert the Strings into int's
for (Strings::iterator i = data.begin(); i != data.end(); ++i){
RevisionNumbers revisionsGroup;
string packedNumbers = *i;
Strings tokens = tokenizeString(packedNumbers, seperator);
for (Strings::iterator j = tokens.begin(); j != tokens.end(); ++j){
int getRevision;
bool succeed = string2Int(*j, getRevision);
if(!succeed)
throw Error(format("Cannot read revision number from db of path '%1%'") % statePath);
revisionsGroup.push_back(getRevision);
}
revisions.push_back(revisionsGroup);
string getRevisionS = *i;
int getRevision;
bool succeed = string2Int(getRevisionS, getRevision);
if(!succeed)
throw Error(format("Cannot read revision number from db of path '%1%'") % statePath);
revisions.push_back(getRevision);
}
return succeed;

View file

@ -117,11 +117,11 @@ public:
/* Set the revision number of the statePath and the revision numbers of all state paths in the references closure */
void setStateRevisions(const Transaction & txn, TableId table,
const Path & statePath, const RevisionNumbersSetClosure & revisions, int revision = -1);
const Path & statePath, const RevisionNumbersSet & revisions, int revision = -1);
/* Returns all the revision numbers of the state references closure of the given state path */
bool queryStateRevisions(const Transaction & txn, TableId table,
const Path & statePath, RevisionNumbersClosure & revisions, int revision = -1);
const Path & statePath, RevisionNumbers & revisions, int revision = -1);
/* Returns all available revision numbers of the given state path */
bool queryAvailableStateRevisions(const Transaction & txn, TableId table,

View file

@ -469,7 +469,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
roots under the `references' relation. */
PathSet livePaths;
for (PathSet::const_iterator i = roots.begin(); i != roots.end(); ++i)
computeFSClosure(canonPath(*i), livePaths, true, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO DELETE STATE??
computeFSClosure(canonPath(*i), livePaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO DELETE STATE??
if (gcKeepDerivations) {
for (PathSet::iterator i = livePaths.begin();
@ -480,7 +480,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
turned off). */
Path deriver = queryDeriver(noTxn, *i);
if (deriver != "" && store->isValidPath(deriver))
computeFSClosure(deriver, livePaths, true, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO KEEP STATE
computeFSClosure(deriver, livePaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO KEEP STATE
}
}
@ -493,7 +493,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
for (DerivationOutputs::iterator j = drv.outputs.begin();
j != drv.outputs.end(); ++j)
if (store->isValidPath(j->second.path))
computeFSClosure(j->second.path, livePaths, true, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO KEEP STATE
computeFSClosure(j->second.path, livePaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO KEEP STATE
}
}
@ -518,7 +518,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
PathSet tempRootsClosed;
for (PathSet::iterator i = tempRoots.begin(); i != tempRoots.end(); ++i)
if (store->isValidPath(*i))
computeFSClosure(*i, tempRootsClosed, true, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO .... STATE
computeFSClosure(*i, tempRootsClosed, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO .... STATE
else
tempRootsClosed.insert(*i);

View file

@ -116,7 +116,7 @@ static TableId dbStateCounters = 0;
*/
static TableId dbStateInfo = 0;
/* dbStateRevisions :: StatePath -> RevisionNumbersClosure
/* dbStateRevisions :: StatePath -> RevisionNumbers
This table lists the statepaths + recursive (indirect) references and the revision numbers of their repositorys
@ -1491,7 +1491,7 @@ void setStatePathsInterval(const PathSet & statePaths, const vector<int> & inter
int n=0;
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
{
printMsg(lvlError, format("Set interval of PATH: %1%") % *i);
//printMsg(lvlError, format("Set interval of PATH: %1%") % *i);
int interval=0;
if(!allZero)
@ -1597,9 +1597,11 @@ PathSet mergeNewDerivationIntoList(const Path & storepath, const Path & newdrv,
TODO Change comment, this can also take state paths
*/
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState)
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision)
{
computeFSClosure(storeOrstatePath, paths, withComponents, withState);
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!
computeFSClosure(storeOrstatePath, paths, withComponents, withState, revision);
if (includeOutputs) {
for (PathSet::iterator i = paths.begin();
@ -1609,14 +1611,14 @@ void storePathRequisites(const Path & storeOrstatePath, const bool includeOutput
for (DerivationOutputs::iterator j = drv.outputs.begin();
j != drv.outputs.end(); ++j)
if (store->isValidPath(j->second.path))
computeFSClosure(j->second.path, paths, withComponents, withState);
computeFSClosure(j->second.path, paths, withComponents, withState, revision);
}
}
}
void LocalStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState)
void LocalStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision)
{
return nix::storePathRequisites(storeOrstatePath, includeOutputs, paths, withComponents, withState);
return nix::storePathRequisites(storeOrstatePath, includeOutputs, paths, withComponents, withState, revision);
}
/*
@ -1768,7 +1770,6 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
//update all revision numbers (transaction) NEW FUN THAT UPDATES THE REVISIONS
//update all revision numbers + references (transaction)
//update all references
@ -1796,9 +1797,9 @@ void LocalStore::scanAndUpdateAllReferences(const Path & statePath)
void scanAndUpdateAllReferencesRecusively(const Transaction & txn, const Path & storeOrStatePath) //TODO Can also work for statePaths???
{
//get all state references recursively
//get all state current state references recursively
PathSet statePaths;
storePathRequisites(storeOrStatePath, false, statePaths, false, true); //TODO CAN THIS ???
storePathRequisites(storeOrStatePath, false, statePaths, false, true, -1); //TODO CAN THIS ???
//call scanForAllReferences again on all newly found statePaths
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
@ -1820,22 +1821,22 @@ void LocalStore::scanAndUpdateAllReferencesRecusively(const Path & storeOrStateP
return nix::scanAndUpdateAllReferencesRecusively(noTxn, storeOrStatePath);
}
void setStateRevisions(const Transaction & txn, const Path & statePath, const RevisionNumbersSetClosure & revisions, const int revision)
void setStateRevisions(const Transaction & txn, const Path & statePath, const RevisionNumbersSet & revisions, const int revision)
{
nixDB.setStateRevisions(txn, dbStateRevisions, statePath, revisions, revision);
}
void LocalStore::setStateRevisions(const Path & statePath, const RevisionNumbersSetClosure & revisions, const int revision)
void LocalStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision)
{
nix::setStateRevisions(noTxn, statePath, revisions, revision);
}
bool queryStateRevisions(const Transaction & txn, const Path & statePath, RevisionNumbersClosure & revisions, const int revision)
bool queryStateRevisions(const Transaction & txn, const Path & statePath, RevisionNumbers & revisions, const int revision)
{
return nixDB.queryStateRevisions(txn, dbStateRevisions, statePath, revisions, revision);
}
bool LocalStore::queryStateRevisions(const Path & statePath, RevisionNumbersClosure & revisions, const int revision)
bool LocalStore::queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision)
{
return nix::queryStateRevisions(noTxn, statePath, revisions, revision);
}

View file

@ -96,15 +96,15 @@ public:
bool isStateDrv(const Derivation & drv);
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState);
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision);
void scanAndUpdateAllReferences(const Path & statePath);
void scanAndUpdateAllReferencesRecusively(const Path & storeOrstatePath);
void setStateRevisions(const Path & statePath, const RevisionNumbersSetClosure & revisions, const int revision);
void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionNumbersClosure & revisions, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision);
bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions);

View file

@ -11,18 +11,18 @@ namespace nix {
Derivation derivationFromPath(const Path & drvPath)
{
assertStorePath(drvPath);
printMsg(lvlError, format("tttttttttttttttttt"));
//printMsg(lvlError, format("tttttttttttttttttt"));
store->ensurePath(drvPath);
printMsg(lvlError, format("uuuuuuuuuuuuuuuuuu"));
//printMsg(lvlError, format("uuuuuuuuuuuuuuuuuu"));
ATerm t = ATreadFromNamedFile(drvPath.c_str());
if (!t) throw Error(format("cannot read aterm from `%1%'") % drvPath);
return parseDerivation(t);
}
void computeFSClosure(const Path & path, PathSet & paths, const bool & withComponents, const bool & withState, bool flipDirection)
void computeFSClosure(const Path & path, PathSet & paths, const bool & withComponents, const bool & withState, const int revision, bool flipDirection)
{
PathSet allPaths;
computeFSClosureRec(path, allPaths, flipDirection);
computeFSClosureRec(path, allPaths, revision, flipDirection);
if(!withComponents && !withState)
throw Error(format("Useless call to computeFSClosure, at leat withComponents or withState must be true"));
@ -50,7 +50,7 @@ void computeFSClosure(const Path & path, PathSet & paths, const bool & withCompo
}
}
void computeFSClosureRec(const Path & path, PathSet & paths, const bool & flipDirection)
void computeFSClosureRec(const Path & path, PathSet & paths, const int revision, const bool & flipDirection)
{
if (paths.find(path) != paths.end()) return; //takes care of double entries
@ -60,19 +60,19 @@ void computeFSClosureRec(const Path & path, PathSet & paths, const bool & flipDi
PathSet stateReferences;
if (flipDirection){
store->queryReferrers(path, references, -1);
store->queryStateReferrers(path, stateReferences, -1);
store->queryReferrers(path, references, revision);
store->queryStateReferrers(path, stateReferences, revision);
}
else{
store->queryReferences(path, references, -1);
store->queryStateReferences(path, stateReferences, -1);
store->queryReferences(path, references, revision);
store->queryStateReferences(path, stateReferences, revision);
}
PathSet allReferences;
allReferences = pathSets_union(references, stateReferences);
for (PathSet::iterator i = allReferences.begin(); i != allReferences.end(); ++i)
computeFSClosureRec(*i, paths, flipDirection);
computeFSClosureRec(*i, paths, revision, flipDirection);
}

View file

@ -24,9 +24,9 @@ Derivation derivationFromPath(const Path & drvPath);
We can currentky only compute the closure of the latsest revision!
returned. */
void computeFSClosure(const Path & storePath, PathSet & paths, const bool & withComponents, const bool & withState, bool flipDirection = false);
void computeFSClosure(const Path & storePath, PathSet & paths, const bool & withComponents, const bool & withState, const int revision, bool flipDirection = false);
void computeFSClosureRec(const Path & path, PathSet & paths, const bool & flipDirection); //private
void computeFSClosureRec(const Path & path, PathSet & paths, const int revision, const bool & flipDirection); //TODO private
/* Return the path corresponding to the output identifier `id' in the
given derivation. */

View file

@ -457,7 +457,7 @@ bool RemoteStore::isStateDrv(const Derivation & drv)
}
//TODO
void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState)
void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision)
{
}
@ -475,13 +475,13 @@ void RemoteStore::scanAndUpdateAllReferencesRecusively(const Path & storeOrstate
}
//TODO
void RemoteStore::setStateRevisions(const Path & statePath, const RevisionNumbersSetClosure & revisions, const int revision)
void RemoteStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision)
{
}
//TODO
bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionNumbersClosure & revisions, const int revision)
bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision)
{
return false;
}

View file

@ -84,15 +84,15 @@ public:
bool isStateDrv(const Derivation & drv);
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState);
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision);
void scanAndUpdateAllReferences(const Path & statePath);
void scanAndUpdateAllReferencesRecusively(const Path & storeOrstatePath);
void setStateRevisions(const Path & statePath, const RevisionNumbersSetClosure & revisions, const int revision);
void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionNumbersClosure & revisions, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision);
bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions);

View file

@ -153,18 +153,11 @@ void checkStatePath(const Derivation & drv)
Error(format("The statepath from the Derivation does not match the recalculated statepath, are u trying to spoof the statepath?"));
}
void calculateStateReposPath(const string & type, const Path statePath, const string subfolder, const string & suffix, const string & stateIdentifier, Path & rootPath, Path & fullPath)
void calculateStateReposPath(const string & type, const Path statePath, const string & suffix, const string & stateIdentifier, Path & path)
{
//This is a little trick: we could use the same hash as the statepath, but we change it so the repository also gets a unique scannable hash
Hash hash = hashString(htSHA256, statePath);
//We also hash repository subfolders the prevent collisions
if(subfolder.length() == 0)
throw Error(format("Cannot create a repository for a subfolder without a name"));
string hash_subfolder = type + ":sha256:" + printHash(hash) + ":" + subfolder;
string subfolder2 = printHash32(compressHash(hashString(htSHA256, hash_subfolder), 20)) + "-" + subfolder;
string suffix_stateIdentifier = stateIdentifier;
if(suffix_stateIdentifier != "")
suffix_stateIdentifier = "-" + suffix_stateIdentifier;
@ -176,28 +169,18 @@ void calculateStateReposPath(const string & type, const Path statePath, const st
checkStoreName(suffix);
checkStoreName(stateIdentifier);
rootPath = nixStoreStateRepos + "/"
path = nixStoreStateRepos + "/"
+ printHash32(compressHash(hashString(htSHA256, s), 20))
+ "-" + suffix + suffix_stateIdentifier;
fullPath = rootPath + "/" + subfolder2;
+ "-" + suffix + suffix_stateIdentifier + "/";
}
Path getStateReposPath(const string & type, const Path statePath, const string subfolder, const string & suffix, const string & stateIdentifier)
Path getStateReposPath(const string & type, const Path statePath, const string & suffix, const string & stateIdentifier)
{
Path fullPath;
Path rootPath;
calculateStateReposPath(type, statePath, subfolder, suffix, stateIdentifier, rootPath, fullPath);
return fullPath;
Path path;
calculateStateReposPath(type, statePath, suffix, stateIdentifier, path);
return path;
}
Path getStateReposRootPath(const string & type, const Path statePath, const string & suffix, const string & stateIdentifier)
{
Path fullPath;
Path rootPath;
calculateStateReposPath(type, statePath, "/", suffix, stateIdentifier, rootPath, fullPath);
return rootPath;
}
Path makeFixedOutputPath(bool recursive,
string hashAlgo, Hash hash, string name)

View file

@ -215,7 +215,7 @@ public:
virtual bool isStateDrv(const Derivation & drv) = 0;
/* TODO */
virtual void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState) = 0;
virtual void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) = 0;
/* TODO */
virtual void scanAndUpdateAllReferences(const Path & statePath) = 0;
@ -224,10 +224,10 @@ public:
virtual void scanAndUpdateAllReferencesRecusively(const Path & storeOrstatePath) = 0;
/* TODO */
virtual void setStateRevisions(const Path & statePath, const RevisionNumbersSetClosure & revisions, const int revision) = 0;
virtual void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) = 0;
/* TODO */
virtual bool queryStateRevisions(const Path & statePath, RevisionNumbersClosure & revisions, const int revision) = 0;
virtual bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision) = 0;
/* TODO */
virtual bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions) = 0;
@ -268,13 +268,11 @@ Path makeStatePath(const string & componentHash, const string & suffix, const st
void checkStatePath(const Derivation & drv);
/* Calculates a unique store state repos path and also the root path */
void calculateStateReposPath(const string & type, const Path statePath, const string subfolder, const string & suffix, const string & stateIdentifier, Path & rootPath, Path & fullPath);
void calculateStateReposPath(const string & type, const Path statePath, const string & suffix, const string & stateIdentifier, Path & path);
/* Returns the full repository path */
Path getStateReposPath(const string & type, const Path statePath, const string subfolder, const string & suffix, const string & stateIdentifier);
/* Returns the root path containing the repository's */
Path getStateReposRootPath(const string & type, const Path statePath, const string & suffix, const string & stateIdentifier);
Path getStateReposPath(const string & type, const Path statePath, const string & suffix, const string & stateIdentifier);
/* This is the preparatory part of addToStore() and addToStoreFixed();
it computes the store path to which srcPath is to be copied.

View file

@ -37,72 +37,54 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
PathSet intervalPaths;
//Make sure the 'root' path which holds the repositorys exists, so svn doenst complain.
string repos_root_path = getStateReposRootPath("stateOutput:staterepospath", stateDir, drvName, stateIdentifier);
//check if we can create state and staterepos dirs
//TODO
Strings p_args;
p_args.push_back("-p");
p_args.push_back(repos_root_path);
runProgram_AndPrintOutput("mkdir", true, p_args, "mkdir");
//Create a repository for this state location
string repos = getStateReposPath("stateOutput:staterepospath", stateDir, drvName, stateIdentifier);
printMsg(lvlTalkative, format("Adding statedir '%1%' from repository '%2%'") % stateDir % repos);
if(IsDirectory(repos))
printMsg(lvlTalkative, format("Repos %1% already exists, so we use that repository") % repos);
else{
Strings p_args;
p_args.push_back("create");
p_args.push_back(repos);
runProgram_AndPrintOutput(svnadminbin, true, p_args, "svnadmin"); //TODO create as nixbld.nixbld chmod 700... can you still commit then ??
}
//TODO check if we can create state and staterepos dirs
string statedir_svn = stateDir + "/.svn/";
if( ! IsDirectory(statedir_svn) ){
Strings p_args;
p_args.push_back("checkout");
p_args.push_back("file://" + repos);
p_args.push_back(stateDir);
runProgram_AndPrintOutput(svnbin, true, p_args, "svn"); //TODO checkout as user
}
else
printMsg(lvlTalkative, format("Statedir %1% already exists, so dont check out its repository again") % statedir_svn);
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
DerivationStateOutputDir d = i->second;
string thisdir = d.path;
string fullstatedir = stateDir + "/" + thisdir;
Path statePath = fullstatedir; //TODO call coerce function
Path fullstatedir = stateDir + "/" + thisdir;
//Check if and how this dir needs to be versioned
if(d.type == "none"){
Strings p_args;
p_args.push_back("-p");
p_args.push_back(fullstatedir);
runProgram_AndPrintOutput("mkdir", true, p_args, "mkdir");
continue;
}
Strings p_args;
p_args.push_back("-p");
p_args.push_back(fullstatedir);
runProgram_AndPrintOutput("mkdir", true, p_args, "mkdir");
//Create a repository for this state location
string repos = getStateReposPath("stateOutput:staterepospath", stateDir, thisdir, drvName, stateIdentifier);
if(IsDirectory(repos))
printMsg(lvlTalkative, format("Repos %1% already exists, so we use that repository") % repos);
else{
Strings p_args;
p_args.push_back("create");
p_args.push_back(repos);
runProgram_AndPrintOutput(svnadminbin, true, p_args, "svnadmin"); //TODO create as nixbld.nixbld chmod 700... can you still commit then ??
}
if(d.type == "interval"){
intervalPaths.insert(statePath);
}
printMsg(lvlTalkative, format("Adding state subdir: %1% to %2% from repository %3%") % thisdir % fullstatedir % repos);
string fullstatedir_svn = fullstatedir + "/.svn/";
if( ! IsDirectory(fullstatedir_svn) ){
Strings p_args;
p_args.push_back("checkout");
p_args.push_back("file://" + repos);
p_args.push_back(fullstatedir);
runProgram_AndPrintOutput(svnbin, true, p_args, "svn"); //TODO checkout as user
}
else
printMsg(lvlTalkative, format("Statedir %1% already exists, so dont check out its repository again") % fullstatedir_svn);
intervalPaths.insert(fullstatedir);
}
}
//Initialize the counters for the statePaths that have an interval to 0
vector<int> empty;
store->setStatePathsInterval(intervalPaths, empty, true);
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
//Initialize the revisions recursively
}
}