diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 4dc10dd09..d10382ef2 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1377,14 +1377,11 @@ void DerivationGoal::startBuilder() tmpDir = createTempDir(); /* Create the state directory where the component can store it's state files place */ - //TODO - - //TODO include addDirsBefore ... - //if(enableState){ ... - //stateDir = createStateDirs(drv.stateOutputDirs, drv.stateOutputs); - //} - - //TODO create the startupscript + //printMsg(lvlError, format("STATE: `%1%'") % ); + //We only create state dirs when state is enabled and when the dirs need to be created before the installation + if(drv.stateOutputs.size() != 0) + if(drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall()) + createStateDirs(drv.stateOutputDirs, drv.stateOutputs); /* For convenience, set an environment pointing to the top build directory. */ @@ -1616,6 +1613,11 @@ void DerivationGoal::computeClosure() map allReferences; map contentHashes; + //We create state dirs only when state is enabled and when the dirs need to be created after the installation + if(drv.stateOutputs.size() != 0) + if(!drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall()) + createStateDirs(drv.stateOutputDirs, drv.stateOutputs); + /* Check whether the output paths were created, and grep each output path to determine what other paths it references. Also make all output paths read-only. */ diff --git a/src/libstore/derivations-ast.def b/src/libstore/derivations-ast.def index 4aff2c6b4..dc13f53c9 100644 --- a/src/libstore/derivations-ast.def +++ b/src/libstore/derivations-ast.def @@ -10,15 +10,14 @@ Derive | ATermList ATermList ATermList ATermList ATermList string string ATermLi | 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 thinks that it should be removed to prevent confusion & duplication - -#!!!!!!!!Change the string "DeriveWithOutState" in derivations.ast-def.cc to "Derive" -#TODO, make this automatic.. - -DeriveWithOutState | ATermList ATermList ATermList string string ATermList ATermList | ATerm | +#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 | + + Closure | ATermList ATermList | ATerm | OldClosure | | string ATermList | ATerm | OldClosureElem | diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index f8071bfc7..9fe1d3914 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -4,6 +4,7 @@ typedef struct _ATerm * ATerm; #include "hash.hh" +#include "util.hh" #include @@ -55,6 +56,14 @@ struct DerivationStateOutput this->synchronization = synchronization; this->createDirsBeforeInstall = createDirsBeforeInstall; } + + bool getEnabled(){ + return string2bool(enabled); + } + + bool getCreateDirsBeforeInstall(){ + return string2bool(createDirsBeforeInstall); + } }; struct DerivationStateOutputDir diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 7c8354846..55e954499 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -974,5 +974,38 @@ string bool2string(const bool b) return "false"; } +bool string2bool(const string & s) +{ + if(s == "true") + return true; + else if(s == "false") + return false; + else{ + throw Error(format("cannot convert string: `%1%' to bool") % s); + quickExit(1); + return false; + } +} + +string triml(const string & s) { + string news = s; + int pos(0); + for ( ; news[pos]==' ' || news[pos]=='\t'; ++pos ); + news.erase(0, pos); + return news; +} + +string trimr(const string & s) { + string news = s; + int pos(news.size()); + for ( ; pos && news[pos-1]==' ' || news[pos]=='\t'; --pos ); + news.erase(pos, news.size()-pos); + return news; +} + +string trim(const string & s) { + return triml(trimr(s)); +} + } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 0af444c6b..d14bbf7d0 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -279,10 +279,18 @@ bool statusOk(int status); string int2String(int n); bool string2Int(const string & s, int & n); -/* Parse a bool to a string */ +/* Parse a bool to a string and back */ string bool2string(const bool b); +bool string2bool(const string & s); + +//return modified string s with spaces trimmed from left +string triml(const string & s); +//return modified string s with spaces trimmed from right +string trimr(const string & s); +//return modified string s with spaces trimmed from edges +string trim(const string & s); + } - #endif /* !__UTIL_H */