mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 20:20:58 +01:00
Added beginnnings of getStatePathClosure and GetDrv in local-store.cc, next: setting up variables in nix-state to recursively commit state
This commit is contained in:
parent
fbd1b78a9d
commit
cbd0d39583
13 changed files with 210 additions and 79 deletions
|
|
@ -6,18 +6,19 @@ Derive | ATermList ATermList ATermList ATermList ATermList string string ATermLi
|
|||
| string string | ATerm | EnvBinding |
|
||||
| string ATermList | ATerm | DerivationInput |
|
||||
| string string string string | ATerm | DerivationOutput |
|
||||
| string string string string string string string string | ATerm | DerivationStateOutput |
|
||||
| string string string string string string string string string string | ATerm | DerivationStateOutput |
|
||||
| string string string | ATerm | DerivationStateOutputDir |
|
||||
|
||||
#We use DeriveWithOutState to create derivations that dont use state, and thus dont have the stateDerivationStateOutput and DerivationStateOutputDir in their derivation
|
||||
#Ive put this in because eelco requested it, and its easy to stay backwards compatible, but ultimately I think that it should be removed to prevent confusion & duplication
|
||||
#The function will be called matchDerivateWithOutState, but it will match the Derive term to remain backwards compatible
|
||||
|
||||
Derive | ATermList ATermList ATermList string string ATermList ATermList | ATerm | DeriveWithOutState
|
||||
| string string | ATerm | EnvBindingWithOutState |
|
||||
| string ATermList | ATerm | DerivationInputWithOutState |
|
||||
| string string string string | ATerm | DerivationOutputWithOutState |
|
||||
|
||||
|
||||
#end drv without state
|
||||
|
||||
Closure | ATermList ATermList | ATerm | OldClosure |
|
||||
| string ATermList | ATerm | OldClosureElem |
|
||||
|
|
|
|||
|
|
@ -92,18 +92,20 @@ Derivation parseDerivation(ATerm t)
|
|||
if(withState){
|
||||
//parse state part
|
||||
for (ATermIterator i(stateOuts); i; ++i) {
|
||||
ATerm id, statepath, hashAlgo, hash, enabled, shared, synchronization, createDirsBeforeInstall;
|
||||
if (!matchDerivationStateOutput(*i, id, statepath, hashAlgo, hash, enabled, shared, synchronization, createDirsBeforeInstall))
|
||||
ATerm id, statepath, hashAlgo, hash, stateIdentifier, enabled, shared, synchronization, createDirsBeforeInstall, runtimeStateParamters;
|
||||
if (!matchDerivationStateOutput(*i, id, statepath, hashAlgo, hash, stateIdentifier, enabled, shared, synchronization, createDirsBeforeInstall, runtimeStateParamters))
|
||||
throwBadDrv(t);
|
||||
DerivationStateOutput stateOut;
|
||||
stateOut.statepath = aterm2String(statepath);
|
||||
//checkPath(stateOut.path); //should we check the statpath .... ???
|
||||
stateOut.hashAlgo = aterm2String(hashAlgo);
|
||||
stateOut.hash = aterm2String(hash);
|
||||
stateOut.stateIdentifier = aterm2String(stateIdentifier);
|
||||
stateOut.enabled = aterm2String(enabled);
|
||||
stateOut.shared = aterm2String(shared);
|
||||
stateOut.synchronization = aterm2String(synchronization);
|
||||
stateOut.createDirsBeforeInstall = aterm2String(createDirsBeforeInstall);
|
||||
stateOut.runtimeStateParamters = aterm2String(runtimeStateParamters);
|
||||
drv.stateOutputs[aterm2String(id)] = stateOut;
|
||||
}
|
||||
}
|
||||
|
|
@ -182,10 +184,12 @@ ATerm unparseDerivation(const Derivation & drv)
|
|||
toATerm(i->second.statepath),
|
||||
toATerm(i->second.hashAlgo),
|
||||
toATerm(i->second.hash),
|
||||
toATerm(i->second.stateIdentifier),
|
||||
toATerm(i->second.enabled),
|
||||
toATerm(i->second.shared),
|
||||
toATerm(i->second.synchronization),
|
||||
toATerm(i->second.createDirsBeforeInstall)
|
||||
toATerm(i->second.createDirsBeforeInstall),
|
||||
toATerm(i->second.runtimeStateParamters)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,22 +39,30 @@ struct DerivationStateOutput
|
|||
Path statepath;
|
||||
string hashAlgo;
|
||||
string hash;
|
||||
string enabled;
|
||||
string stateIdentifier; //the identifier
|
||||
string enabled; //enable or disable state
|
||||
string shared; //none, full, group
|
||||
string synchronization; //none, exclusive-lock-on-own-state-dir, exclusive-lock-on-all-(sub)-states-dir
|
||||
string createDirsBeforeInstall;
|
||||
string synchronization; //none (no locks), exclusive-lock-on-own-state-dir, exclusive-lock-on-all-(sub)-states-dir
|
||||
|
||||
string commitReferences; //TODO none, direct, recursive-all
|
||||
string commitBinaries; //TODO list of binaries that need (or not) to be committed when these binaries are called
|
||||
|
||||
string createDirsBeforeInstall; //if true: creates state dirs before installation
|
||||
string runtimeStateParamters; //if not empty: these are the runtime parameters where state can be found (you can use $statepath here)
|
||||
DerivationStateOutput()
|
||||
{
|
||||
}
|
||||
DerivationStateOutput(Path statepath, string hashAlgo, string hash, string enabled, string shared, string synchronization, string createDirsBeforeInstall)
|
||||
DerivationStateOutput(Path statepath, string hashAlgo, string hash, string stateIdentifier, string enabled, string shared, string synchronization, string createDirsBeforeInstall, string runtimeStateParamters)
|
||||
{
|
||||
this->statepath = statepath;
|
||||
this->hashAlgo = hashAlgo;
|
||||
this->hash = hash;
|
||||
this->stateIdentifier = stateIdentifier;
|
||||
this->enabled = enabled;
|
||||
this->shared = shared;
|
||||
this->synchronization = synchronization;
|
||||
this->createDirsBeforeInstall = createDirsBeforeInstall;
|
||||
this->runtimeStateParamters = runtimeStateParamters;
|
||||
}
|
||||
|
||||
bool getEnabled(){
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
#include "aterm.hh"
|
||||
#include "derivations-ast.hh"
|
||||
#include "worker-protocol.hh"
|
||||
|
||||
#include "derivations.hh"
|
||||
#include "misc.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
|
@ -1107,7 +1110,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("PATH: %1%") % *i);
|
||||
printMsg(lvlError, format("Set interval of PATH: %1%") % *i);
|
||||
|
||||
int interval=0;
|
||||
if(!allZero)
|
||||
|
|
@ -1127,19 +1130,21 @@ void LocalStore::setStatePathsInterval(const PathSet & statePaths, const vector<
|
|||
|
||||
vector<int> getStatePathsInterval(const PathSet & statePaths)
|
||||
{
|
||||
|
||||
Transaction txn(nixDB); //TODO should u do a transaction here? ... this might delay the process ...
|
||||
|
||||
string data;
|
||||
Paths referers;
|
||||
|
||||
vector<int> intervals;
|
||||
string data;
|
||||
|
||||
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i){
|
||||
|
||||
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
|
||||
{
|
||||
nixDB.queryString(txn, dbStateCounters, *i, data);
|
||||
printMsg(lvlError, format("Data %1%") % data);
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
printMsg(lvlError, format("Data %1%") % data); //TODO
|
||||
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
return intervals;
|
||||
}
|
||||
|
||||
|
|
@ -1149,6 +1154,58 @@ vector<int> LocalStore::getStatePathsInterval(const PathSet & statePaths)
|
|||
}
|
||||
|
||||
|
||||
Derivation getStateDerivation(const Path & path)
|
||||
{
|
||||
Transaction txn(nixDB); //TODO should u do a transaction here? ... this might delay the process ...
|
||||
|
||||
string data;
|
||||
|
||||
//Get derivations of references
|
||||
nixDB.queryString(txn, dbDerivers, path, data);
|
||||
printMsg(lvlError, format("DERIVERS %1%") % data);
|
||||
|
||||
txn.commit();
|
||||
|
||||
Derivation drv = derivationFromPath(data);
|
||||
if(drv.stateOutputs.size() == 0)
|
||||
throw Error(format("This path is not a state derivation: `%1%'") % path);
|
||||
|
||||
return drv;
|
||||
}
|
||||
|
||||
Derivation LocalStore::getStateDerivation(const Path & path)
|
||||
{
|
||||
return nix::getStateDerivation(path);
|
||||
}
|
||||
|
||||
//TODO direct or all recursive parameter
|
||||
//TODO check if these are state components
|
||||
PathSet getStateReferencesClosure(const Path & path)
|
||||
{
|
||||
Transaction txn(nixDB); //TODO should u do a transaction here? ... this might delay the process ...
|
||||
|
||||
Strings data;
|
||||
PathSet paths;
|
||||
|
||||
Paths referencesKeys;
|
||||
nixDB.queryStrings(txn, dbReferences, path, data);
|
||||
for (Strings::iterator i = data.begin(); i != data.end(); ++i)
|
||||
{
|
||||
//printMsg(lvlError, format("References: `%1%'") % *i);
|
||||
paths.insert(*i);
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
|
||||
return paths;
|
||||
|
||||
}
|
||||
|
||||
PathSet LocalStore::getStateReferencesClosure(const Path & path)
|
||||
{
|
||||
return nix::getStateReferencesClosure(path);
|
||||
}
|
||||
|
||||
|
||||
/* Upgrade from schema 1 (Nix <= 0.7) to schema 2 (Nix >= 0.8). */
|
||||
static void upgradeStore07()
|
||||
|
|
|
|||
|
|
@ -79,6 +79,10 @@ public:
|
|||
void setStatePathsInterval(const PathSet & statePath, const vector<int> & intervals, bool allZero = false);
|
||||
|
||||
vector<int> getStatePathsInterval(const PathSet & statePaths);
|
||||
|
||||
Derivation getStateDerivation(const Path & path);
|
||||
|
||||
PathSet getStateReferencesClosure(const Path & path);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -388,5 +388,19 @@ vector<int> RemoteStore::getStatePathsInterval(const PathSet & statePaths)
|
|||
return intervals;
|
||||
}
|
||||
|
||||
//TODO
|
||||
Derivation RemoteStore::getStateDerivation(const Path & path)
|
||||
{
|
||||
Derivation d;
|
||||
return d;
|
||||
}
|
||||
|
||||
//TODO
|
||||
PathSet RemoteStore::getStateReferencesClosure(const Path & path)
|
||||
{
|
||||
PathSet empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,11 @@ public:
|
|||
void setStatePathsInterval(const PathSet & statePath, const vector<int> & intervals, bool allZero = false);
|
||||
|
||||
vector<int> getStatePathsInterval(const PathSet & statePaths);
|
||||
|
||||
Derivation getStateDerivation(const Path & path);
|
||||
|
||||
PathSet getStateReferencesClosure(const Path & path);
|
||||
|
||||
|
||||
private:
|
||||
AutoCloseFD fdSocket;
|
||||
|
|
|
|||
|
|
@ -75,34 +75,44 @@ Path makeStorePath(const string & type, const Hash & hash, const string & suffix
|
|||
checkStoreName(suffix);
|
||||
|
||||
return nixStore + "/"
|
||||
+ printHash32(compressHash(hashString(htSHA256, s), 20))
|
||||
+ printHash32(compressHash(hashString(htSHA256, s), 20)) //TODO maybe also add a suffix_stateIdentifier when: there is state & no runtime state args & ... ?
|
||||
+ "-" + suffix;
|
||||
}
|
||||
|
||||
Path makeStatePath(const string & type, const Hash & hash, const string & suffix)
|
||||
Path makeStatePath(const string & type, const Hash & hash, const string & suffix, const string & stateIdentifier)
|
||||
{
|
||||
string suffix_stateIdentifier = stateIdentifier;
|
||||
if(suffix_stateIdentifier != "")
|
||||
suffix_stateIdentifier = "-" + suffix_stateIdentifier;
|
||||
|
||||
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
|
||||
string s = type + ":sha256:" + printHash(hash) + ":"
|
||||
+ nixStoreState + ":" + suffix;
|
||||
+ nixStoreState + ":" + suffix + ":" + stateIdentifier;
|
||||
|
||||
checkStoreName(suffix); //should this be here?
|
||||
checkStoreName(suffix);
|
||||
checkStoreName(stateIdentifier);
|
||||
|
||||
return nixStoreState + "/"
|
||||
+ printHash32(compressHash(hashString(htSHA256, s), 20))
|
||||
+ "-" + suffix;
|
||||
+ "-" + suffix + suffix_stateIdentifier;
|
||||
}
|
||||
|
||||
Path makeStateReposPath(const string & type, const Hash & hash, const string & suffix)
|
||||
Path makeStateReposPath(const string & type, const Hash & hash, const string & suffix, const string & stateIdentifier)
|
||||
{
|
||||
string suffix_stateIdentifier = stateIdentifier;
|
||||
if(suffix_stateIdentifier != "")
|
||||
suffix_stateIdentifier = "-" + suffix_stateIdentifier;
|
||||
|
||||
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
|
||||
string s = type + ":sha256:" + printHash(hash) + ":"
|
||||
+ nixStoreState + ":" + suffix;
|
||||
|
||||
checkStoreName(suffix); //should this be here?
|
||||
+ nixStoreState + ":" + suffix + ":" + stateIdentifier;
|
||||
|
||||
checkStoreName(suffix);
|
||||
checkStoreName(stateIdentifier);
|
||||
|
||||
return nixStoreStateRepos + "/"
|
||||
+ printHash32(compressHash(hashString(htSHA256, s), 20))
|
||||
+ "-" + suffix;
|
||||
+ "-" + suffix + suffix_stateIdentifier;
|
||||
}
|
||||
|
||||
Path makeFixedOutputPath(bool recursive,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "hash.hh"
|
||||
#include "serialise.hh"
|
||||
#include "derivations.hh"
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
|
@ -185,6 +186,13 @@ public:
|
|||
|
||||
/* TODO */
|
||||
virtual vector<int> getStatePathsInterval(const PathSet & statePaths) = 0;
|
||||
|
||||
/* TODO */
|
||||
virtual Derivation getStateDerivation(const Path & path) = 0;
|
||||
|
||||
/* TODO */
|
||||
virtual PathSet getStateReferencesClosure(const Path & path) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -211,10 +219,10 @@ Path makeFixedOutputPath(bool recursive,
|
|||
string hashAlgo, Hash hash, string name);
|
||||
|
||||
/* Constructs a unique store state path name. */
|
||||
Path makeStatePath(const string & type, const Hash & hash, const string & suffix);
|
||||
Path makeStatePath(const string & type, const Hash & hash, const string & suffix, const string & stateIdentifier);
|
||||
|
||||
/* Constructs a unique store state repos path name. */
|
||||
Path makeStateReposPath(const string & type, const Hash & hash, const string & suffix);
|
||||
Path makeStateReposPath(const string & type, const Hash & hash, const string & suffix, const string & stateIdentifier);
|
||||
|
||||
|
||||
/* This is the preparatory part of addToStore() and addToStoreFixed();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
|
|||
Path statePath = stateOutputs.find("state")->second.statepath;
|
||||
string stateDir = statePath;
|
||||
string drvName = env.find("name")->second;
|
||||
string stateIdentifier = stateOutputs.find("state")->second.stateIdentifier;
|
||||
|
||||
//Convert the map into a sortable vector
|
||||
vector<DerivationStateOutputDir> stateDirsVector;
|
||||
|
|
@ -49,15 +50,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
|
|||
string fullstatedir = stateDir + "/" + thisdir;
|
||||
Path statePath = fullstatedir; //TODO call coerce function
|
||||
|
||||
//calc create repos for this state location
|
||||
Hash hash = hashString(htSHA256, stateDir + thisdir);
|
||||
string repos = makeStateReposPath("stateOutput:staterepospath", hash, drvName);
|
||||
|
||||
//Were going to execute svn shell commands
|
||||
executeAndPrintShellCommand(svnadminbin + " create " + repos, "svnadmin"); //TODO create as nixbld.nixbld chmod 700
|
||||
|
||||
//TODO REPLACE TRUE INTO VAR
|
||||
|
||||
//TODO REPLACE TRUE INTO VAR OF CREATEING DIRS BEFORE OR AFTER INSTALL
|
||||
//Check if and how this dir needs to be versioned
|
||||
if(d.type == "none"){
|
||||
if(true){
|
||||
|
|
@ -66,7 +59,13 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
|
|||
nonversionedpaths.push_back(fullstatedir);
|
||||
continue;
|
||||
}
|
||||
|
||||
//Create a repository for this state location
|
||||
Hash hash = hashString(htSHA256, stateDir + thisdir);
|
||||
string repos = makeStateReposPath("stateOutput:staterepospath", hash, drvName, stateIdentifier);
|
||||
executeAndPrintShellCommand(svnadminbin + " create " + repos, "svnadmin"); //TODO create as nixbld.nixbld chmod 700
|
||||
|
||||
//
|
||||
string checkoutcommand = svnbin + " checkout file://" + repos + " " + fullstatedir;
|
||||
checkoutcommands.push_back(checkoutcommand);
|
||||
subversionedpaths.push_back(fullstatedir);
|
||||
|
|
@ -78,6 +77,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
|
|||
else
|
||||
subversionedpathsInterval.push_back(0);
|
||||
|
||||
//TODO REPLACE TRUE INTO VAR OF CREATEING DIRS BEFORE OR AFTER INSTALL
|
||||
if(true){
|
||||
printMsg(lvlError, format("Adding state subdir: %1% to %2% from repository %3%") % thisdir % fullstatedir % repos);
|
||||
executeAndPrintShellCommand(checkoutcommand, "svn"); //TODO checkout as user
|
||||
|
|
@ -121,6 +121,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
|
|||
}
|
||||
}
|
||||
|
||||
//executes a shell command and captures and prints the output.
|
||||
void executeAndPrintShellCommand(const string & command, const string & commandName)
|
||||
{
|
||||
string tempoutput = "svnoutput.txt";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue