diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 6a2a587bd..6f4863152 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -41,7 +41,7 @@ struct DerivationStateOutput string hash; string enabled; string shared; //none, full, group - string synchronization; //none, ... ? + string synchronization; //none, exclusive-lock-on-own-state-dir, exclusive-lock-on-all-(sub)-states-dir string createDirsBeforeInstall; DerivationStateOutput() { diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index f5aae39c8..87d891b96 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -143,6 +143,7 @@ LocalStore::LocalStore(bool reserveSpace) dbReferrers = nixDB.openTable("referrers", true); /* must be sorted */ dbSubstitutes = nixDB.openTable("substitutes"); dbDerivers = nixDB.openTable("derivers"); + dbStateCounters = nixDB.openTable("statecounters"); int curSchema = 0; Path schemaFN = nixDBPath + "/schema"; @@ -1095,6 +1096,59 @@ void verifyStore(bool checkContents) txn.commit(); } +void setStatePathsInterval(const PathSet & statePaths, const vector & intervals, bool allZero) +{ + if(!allZero && statePaths.size() != intervals.size()){ + throw Error("the number of statepaths and intervals must be equal"); + } + + Transaction txn(nixDB); + + int n=0; + for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i) + { + printMsg(lvlError, format("PATH: %1%") % *i); + + int interval=0; + if(!allZero) + interval = intervals.at(n); + + nixDB.setString(txn, dbStateCounters, *i, int2String(interval)); + n++; + } + + txn.commit(); +} + +void LocalStore::setStatePathsInterval(const PathSet & statePaths, const vector & intervals, bool allZero) +{ + nix::setStatePathsInterval(statePaths, intervals, allZero); +} + +vector getStatePathsInterval(const PathSet & statePaths) +{ + Transaction txn(nixDB); //TODO should u do a transaction here? ... this might delay the process ... + + vector intervals; + string data; + + for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i){ + + nixDB.queryString(txn, dbStateCounters, *i, data); + printMsg(lvlError, format("Data %1%") % data); + } + + txn.commit(); + + return intervals; +} + +vector LocalStore::getStatePathsInterval(const PathSet & statePaths) +{ + return nix::getStatePathsInterval(statePaths); +} + + /* Upgrade from schema 1 (Nix <= 0.7) to schema 2 (Nix >= 0.8). */ static void upgradeStore07() diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 76d14c3a6..f8c659e62 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -75,6 +75,10 @@ public: void collectGarbage(GCAction action, const PathSet & pathsToDelete, bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed); + + void setStatePathsInterval(const PathSet & statePath, const vector & intervals, bool allZero = false); + + vector getStatePathsInterval(const PathSet & statePaths); }; diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 1aab90d38..6de7617e8 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -375,5 +375,18 @@ void RemoteStore::processStderr(Sink * sink, Source * source) throw Error("protocol error processing standard error"); } +//TODO +void RemoteStore::setStatePathsInterval(const PathSet & statePaths, const vector & intervals, bool allZero) +{ + +} + +//TODO +vector RemoteStore::getStatePathsInterval(const PathSet & statePaths) +{ + vector intervals; + return intervals; +} + } diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 19af8c0be..5ac39bf2d 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -63,6 +63,10 @@ public: void collectGarbage(GCAction action, const PathSet & pathsToDelete, bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed); + + void setStatePathsInterval(const PathSet & statePath, const vector & intervals, bool allZero = false); + + vector getStatePathsInterval(const PathSet & statePaths); private: AutoCloseFD fdSocket; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 321f09133..7b2556bd2 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -179,6 +179,12 @@ public: `bytesFreed'. */ virtual void collectGarbage(GCAction action, const PathSet & pathsToDelete, bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed) = 0; + + /* TODO */ + virtual void setStatePathsInterval(const PathSet & statePath, const vector & intervals, bool allZero = false) = 0; + + /* TODO */ + virtual vector getStatePathsInterval(const PathSet & statePaths) = 0; }; diff --git a/src/libstore/store-state.cc b/src/libstore/store-state.cc index cfb31d756..cbab7bb2e 100644 --- a/src/libstore/store-state.cc +++ b/src/libstore/store-state.cc @@ -11,12 +11,14 @@ #include "util.hh" #include "derivations.hh" #include "store-api.hh" +#include "local-store.hh" namespace nix { void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs, const StringPairs & env) { - string stateDir = stateOutputs.find("state")->second.statepath; + Path statePath = stateOutputs.find("state")->second.statepath; + string stateDir = statePath; string drvName = env.find("name")->second; //Convert the map into a sortable vector @@ -37,18 +39,20 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De vector subversionedpathsInterval; vector nonversionedpaths; //of type none, no versioning needed vector checkoutcommands; - + PathSet statePaths; + for (vector::iterator i = stateDirsVector.begin(); i != stateDirsVector.end(); ++i) { DerivationStateOutputDir d = *(i); string thisdir = d.path; 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); - + 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 @@ -67,8 +71,10 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De checkoutcommands.push_back(checkoutcommand); subversionedpaths.push_back(fullstatedir); - if(d.type == "interval") + if(d.type == "interval"){ + statePaths.insert(statePath); subversionedpathsInterval.push_back(d.getInterval()); + } else subversionedpathsInterval.push_back(0); @@ -78,6 +84,10 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De } } + //Add the statePaths that have an interval + vector empty; + store->setStatePathsInterval(statePaths, empty, true); + //create super commit script printMsg(lvlError, format("svnbin=%1%") % svnbin); string subversionedstatepathsarray = "subversionedpaths=( "; diff --git a/src/nix-state/help.txt b/src/nix-state/help.txt index 1f0691b66..f818366ab 100644 --- a/src/nix-state/help.txt +++ b/src/nix-state/help.txt @@ -1,58 +1,11 @@ Usage: nix-state [OPTIONS...] [ARGUMENTS...] -`nix-store' is a tool to manipulate the Nix store. +`nix-state' is a tool to manipulate the Nix state-store and to run programs. Operations: - --realise / -r: ensure path validity; if a derivation, ensure that - validity of the outputs - --add / -A: copy a path to the Nix store - --delete: safely delete paths from the Nix store - --query / -q: query information - --read-log / -l: print build log of given store paths - - --register-substitutes: register a substitute expression (dangerous!) - --clear-substitutes: clear all substitutes - --register-validity: register path validity (dangerous!) - --check-validity: check path validity - - --gc: run the garbage collector - - --dump: dump a path as a Nix archive - --restore: restore a path from a Nix archive - - --init: initialise the Nix database - --verify: verify Nix structures + --realise / -r: ensure path validity; if a derivation, ensure that validity of the outputs --version: output version information --help: display help -Query flags: - - --outputs: query the output paths of a Nix derivation (default) - --requisites / -R: print all paths necessary to realise a path - --references: print all paths referenced by the given path - --referrers: print all paths directly refering to the given path - --referrers-closure: print all paths (in)directly refering to the given path - --tree: print a tree showing the dependency graph of the given paths - --graph: print a dot graph rooted at given paths - -Query switches (not applicable to all queries): - - --use-output: perform query on output of derivation, not derivation itself - --force-realise: realise the path before performing the query - --include-outputs: in `-R' on a derivation, include requisites of outputs - -Garbage collector options: - - --print-roots: print GC roots and exit - --print-live: print live paths and exit - --print-dead: print dead paths and exit - --delete: delete dead paths (default) - -Options: - - --verbose / -v: verbose operation (may be repeated) - --keep-failed / -K: keep temporary directories of failed builds - - --add-root: add garbage collector roots for the result diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index 42e63c165..a302c7b4d 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -8,6 +8,7 @@ #include "db.hh" #include "util.hh" #include "help.txt.hh" +#include "local-store.hh" using namespace nix; @@ -24,14 +25,11 @@ void printHelp() } -static Path gcRoot; -static int rootNr = 0; -static bool indirectRoot = false; - - //Look up the references of all (runtime) dependencies that maintain have state -void commitReferencesClosure(){ +static void opCommitReferencesClosure(Strings opFlags, Strings opArgs) +{ + /* Database nixDB; try { @@ -44,17 +42,17 @@ void commitReferencesClosure(){ Paths referencesKeys; Transaction txn(nixDB); - TableId dbReferences = nixDB.openTable("references"); + TableId dbReferences = nixDB.openTable("statecounters"); nixDB.enumTable(txn, dbReferences, referencesKeys); for (Paths::iterator i = referencesKeys.begin(); i != referencesKeys.end(); ++i) { printMsg(lvlError, format("NIX-STATE: `%1%'") % *i); - } - - - + }*/ + PathSet a; + a.insert("/nix/state/m3h15msjdv1cliqdc3ijj906dzhsf6p0-hellohardcodedstateworld-1.0/log/"); + store->getStatePathsInterval(a); /* @@ -83,6 +81,7 @@ void commitReferencesClosure(){ /* Scan the arguments; find the operation, set global flags, put all other flags in a list, and put all other arguments in another list. */ + void run(Strings args) { Strings opFlags, opArgs; @@ -92,9 +91,10 @@ void run(Strings args) string arg = *i++; Operation oldOp = op; - /* - if (arg == "--realise" || arg == "-r") - op = opRealise; + + if (arg == "--start" || arg == "-r") + op = opCommitReferencesClosure; + /* else if (arg == "--add" || arg == "-A") op = opAdd; else if (arg == "--add-fixed") @@ -103,19 +103,22 @@ void run(Strings args) op = opPrintFixedPath; else if (arg[0] == '-') opFlags.push_back(arg); + */ else opArgs.push_back(arg); if (oldOp && oldOp != op) throw UsageError("only one operation may be specified"); - */ } - commitReferencesClosure(); + //opCommitReferencesClosure(); - //if (!op) throw UsageError("no operation specified"); + if (!op) throw UsageError("no operation specified"); + + /* !!! hack */ + store = openStore(); - //op(opFlags, opArgs); + op(opFlags, opArgs); } diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 88acc79aa..c7cad18d6 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -11,7 +11,6 @@ #include "util.hh" #include "help.txt.hh" - using namespace nix; using std::cin; using std::cout;