From 25117fd1657ec12bd64bdf18d1f87422d5f122fb Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Wed, 30 May 2007 17:16:25 +0000 Subject: [PATCH] the command /nixstate/nix/bin/nix-state --run /nix/store/sig2qgvaayydrwy5hn6b2dm5r2ayhv5s-hellohardcodedstateworld-1.0 now causes state to be checked and comitted --- scripts/Makefile.am | 6 +- scripts/nix-statecommit.sh.in | 92 +++++++++++++++ src/libstore/derivations.hh | 14 ++- src/libstore/local-store.cc | 7 +- src/libstore/store-state.cc | 51 --------- src/libutil/util.cc | 57 ++++++++++ src/libutil/util.hh | 2 + src/nix-state/nix-state.cc | 193 ++++++++++++++++++++------------ src/nix-state/statecommit.sh | 80 +++++++++++++ src/nix-state/statecommitTMP.sh | 78 ------------- 10 files changed, 378 insertions(+), 202 deletions(-) create mode 100755 scripts/nix-statecommit.sh.in create mode 100755 src/nix-state/statecommit.sh delete mode 100755 src/nix-state/statecommitTMP.sh diff --git a/scripts/Makefile.am b/scripts/Makefile.am index e16b36d61..586255f3d 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -4,7 +4,7 @@ bin_SCRIPTS = nix-collect-garbage \ nix-pack-closure nix-unpack-closure \ nix-copy-closure -noinst_SCRIPTS = nix-profile.sh generate-patches.pl find-runtime-roots.pl +noinst_SCRIPTS = nix-profile.sh generate-patches.pl find-runtime-roots.pl nix-statecommit.sh nix-pull nix-push: readmanifest.pm readconfig.pm download-using-manifests.pl @@ -17,6 +17,7 @@ install-exec-local: readmanifest.pm download-using-manifests.pl find-runtime-roo $(INSTALL_PROGRAM) download-using-manifests.pl $(DESTDIR)$(libexecdir)/nix $(INSTALL_PROGRAM) find-runtime-roots.pl $(DESTDIR)$(libexecdir)/nix $(INSTALL_PROGRAM) generate-patches.pl $(DESTDIR)$(libexecdir)/nix + $(INSTALL_PROGRAM) nix-statecommit.sh $(DESTDIR)$(libexecdir)/nix $(INSTALL) -d $(DESTDIR)$(sysconfdir)/nix include ../substitute.mk @@ -32,4 +33,5 @@ EXTRA_DIST = nix-collect-garbage.in \ generate-patches.pl.in \ nix-pack-closure.in nix-unpack-closure.in \ nix-copy-closure.in \ - find-runtime-roots.pl.in + find-runtime-roots.pl.in \ + nix-statecommit.sh.in diff --git a/scripts/nix-statecommit.sh.in b/scripts/nix-statecommit.sh.in new file mode 100755 index 000000000..60453a111 --- /dev/null +++ b/scripts/nix-statecommit.sh.in @@ -0,0 +1,92 @@ +#! /bin/sh +# we cant do a -e since ... + +#check if there are enough arguments, if not, exit with an error + +debug=""; #set to "" for no debugging, set to "echo " to debug the commands + +if [ "$#" != 5 ] ; then + echo "Incorrect number of arguments" + exit 1; +fi + +svnbin=$1 +subversionedpaths=( $2 ) #arrays +subversionedpathsCommitBools=( $3 ) +nonversionedpaths=( $4 ) +checkouts=( $5 ) + +#echo svnbin: $svnbin +#echo subversionedpaths: $subversionedpaths +#echo subversionedpathsCommitBools: $subversionedpathsCommitBools +#echo nonversionedpaths: $nonversionedpaths +#echo checkouts: $checkouts + +i=0 +for path in ${subversionedpaths[@]} +do + if test -d $path; then + cd $path; + + output=$($svnbin stat 2>&1 | grep "is not a working copy"); + if [ "$output" != "" ] ; then #if the dir exists but is not yet an svn dir: create repos, if it doenst exits (is removed or something) than we dont do anything + $debug ${checkouts[$i]}; + fi + + if [ "${subversionedpathsCommitBools[$i]}" = "true" ]; then #Check if we need to commit this folder + + echo "Entering $path" + + allsubdirs=( $(echo *) ) #TODO, maybe also add hidden files starting with a '.' , but we dont want to add .svn dirs + + subdirs=(); + for subdir in ${allsubdirs[@]} #add all, exlucding explicity stated direct versioned-subdirs or explicity stated nonversioned-subdirs + do #this is only to prevent some warnings, ultimately we would like svn add to have a option 'exclude dirs' + subdir="$(pwd)/$subdir/"; + exclude=0; + + for svnp in ${subversionedpaths[@]} #check if the subdir is in the list of subverioned paths + do + if [ "$svnp" = "$subdir" ]; then + exclude=1; + #echo "exclude versioned $svnp" + fi + done + + for nonvp in ${nonversionedpaths[@]} #check if the subdir is in the list of dirs that aren't supposed to be versioned + do + if [ "$nonvp" = "$subdir" ]; then + exclude=1; + #echo "exclude nonversioned $svnp" + fi + done + + if [ $exclude = 0 ]; then #Exclude the subdir if nessecary + subdirs[${#subdirs[*]}]=$subdir + fi + done + + if [ "$subdirs" != "" ]; then + echo "adding ${subdirs[@]}" + $debug svn add ${subdirs[@]} #add all subdirs + + for revpath in ${nonversionedpaths[@]} #We need to revert sub-sub* dirs, since these havent been excluded + do + if test -d $revpath; then + if [ "${revpath:0:${#path}}" == "$path" ]; then + echo "Revert $revpath"; + $debug svn revert $revpath; + fi + fi + done + + $debug svn -m "" commit; #Finally, we commit + fi + + fi + + cd - &> /dev/null; + fi + let "i+=1" +done + diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index a55f3bd34..dce7cefcb 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -42,7 +42,7 @@ struct DerivationStateOutput string stateIdentifier; //the identifier string enabled; //enable or disable state string shared; //none, full, group - string synchronization; //none (no locks), exclusive-lock-on-own-state-dir, exclusive-lock-on-all-(sub)-states-dir + string synchronization; //none (no locks), exclusive-lock, recursive-exclusive-lock 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 @@ -54,6 +54,15 @@ struct DerivationStateOutput } DerivationStateOutput(Path statepath, string hashAlgo, string hash, string stateIdentifier, string enabled, string shared, string synchronization, string createDirsBeforeInstall, string runtimeStateParamters) { + if(shared != "none" || shared != "full" || shared != "group") + throw Error(format("shared '%1%' is not a correct type") % shared); + if(synchronization != "none" || synchronization != "exclusive-lock" || synchronization != "recursive-exclusive-lock") + throw Error(format("synchronization '%1%' is not a correct type") % synchronization); + + //TODO + //commitReferences + //commitBinaries + this->statepath = statepath; this->hashAlgo = hashAlgo; this->hash = hash; @@ -84,6 +93,9 @@ struct DerivationStateOutputDir } DerivationStateOutputDir(string path, string type, string interval) { + if(type != "none" || type != "manual" || type != "interval" || type != "full") + throw Error(format("interval '%1%' is not a correct type") % type); + this->path = path; this->type = type; this->interval = interval; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 603b586fa..2d1d6f2f4 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1140,7 +1140,12 @@ vector getStatePathsInterval(const PathSet & statePaths) for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i) { nixDB.queryString(txn, dbStateCounters, *i, data); - printMsg(lvlError, format("Data %1%") % data); //TODO + + //TODO check if every key returns a value from the db + + int n; + if (!string2Int(data, n)) throw Error("number expected"); + intervals.push_back(n); } txn.commit(); diff --git a/src/libstore/store-state.cc b/src/libstore/store-state.cc index 141c23b16..0fcff0260 100644 --- a/src/libstore/store-state.cc +++ b/src/libstore/store-state.cc @@ -67,56 +67,5 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De store->setStatePathsInterval(intervalPaths, empty, true); } -//executes a shell command and captures and prints the output. -void executeAndPrintShellCommand(const string & command, const string & commandName) -{ - string tempoutput = "svnoutput.txt"; - string newcommand = command + " > " + tempoutput; - - int kidstatus, deadpid; - pid_t kidpid = fork(); - switch (kidpid) { - case -1: - throw SysError("unable to fork"); - case 0: - try { // child - int rv = system(newcommand.c_str()); - //int rv = execlp(svnbin.c_str(), svnbin.c_str(), ">", tempoutput.c_str(), NULL); //TODO make this work ... ? - - string line; - std::ifstream myfile (tempoutput.c_str()); - if (myfile.is_open()){ - while (! myfile.eof() ) - { - getline (myfile,line); - if(trim(line) != "") - printMsg(lvlError, format("[%2%]: %1%") % line % commandName); - } - myfile.close(); - } - else{ - throw SysError("svn state error"); - quickExit(1); - } - - if (rv == -1) { - throw SysError("svn state error"); - quickExit(99); - } - quickExit(0); - - } catch (std::exception & e) { - std::cerr << format("state child error: %1%\n") % e.what(); - quickExit(1); - } - } - deadpid = waitpid(kidpid, &kidstatus, 0); - if (deadpid == -1) { - std::cerr << format("state child waitpid error\n"); - quickExit(1); - } - - remove(tempoutput.c_str()); //Remove the tempoutput file -} } diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 55e954499..cdd5f5c4d 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include @@ -1007,5 +1009,60 @@ string trim(const string & s) { return triml(trimr(s)); } + +//executes a shell command and captures and prints the output. + +//TODO , check if we can integrate with runProgram + +void executeAndPrintShellCommand(const string & command, const string & commandName) +{ + string tempoutput = "svnoutput.txt"; + string newcommand = command + " &> " + tempoutput; //the &> sends also stderr to stdout + + int kidstatus, deadpid; + pid_t kidpid = fork(); + switch (kidpid) { + case -1: + throw SysError("unable to fork"); + case 0: + try { // child + int rv = system(newcommand.c_str()); + //int rv = execlp(svnbin.c_str(), svnbin.c_str(), ">", tempoutput.c_str(), NULL); //TODO make this work ... ? + + string line; + std::ifstream myfile (tempoutput.c_str()); + if (myfile.is_open()){ + while (! myfile.eof() ) + { + getline (myfile,line); + if(trim(line) != "") + printMsg(lvlError, format("[%2%]: %1%") % line % commandName); + } + myfile.close(); + } + else{ + throw SysError("svn state error"); + quickExit(1); + } + + if (rv == -1) { + throw SysError("svn state error"); + quickExit(99); + } + quickExit(0); + + } catch (std::exception & e) { + std::cerr << format("state child error: %1%\n") % e.what(); + quickExit(1); + } + } + deadpid = waitpid(kidpid, &kidstatus, 0); + if (deadpid == -1) { + std::cerr << format("state child waitpid error\n"); + quickExit(1); + } + + remove(tempoutput.c_str()); //Remove the tempoutput file +} } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index d14bbf7d0..75da18770 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -290,6 +290,8 @@ string trimr(const string & s); //return modified string s with spaces trimmed from edges string trim(const string & s); +//excecute a shell command +void executeAndPrintShellCommand(const string & command, const string & commandName); } diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index c970adcf7..b495ea511 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -24,8 +24,47 @@ void printHelp() cout << string((char *) helpText, sizeof helpText); } +// + +static Derivation getDerivation_oneArgumentNoFlags(const Strings opFlags, const Strings opArgs) +{ + if (!opFlags.empty()) throw UsageError("unknown flag"); + if (opArgs.size() != 1) throw UsageError("only one argument allowed"); + string path = *opArgs.begin(); + string component = path; //TODO Parse + Path componentPath = component; //TODO call coerce function + return store->getStateDerivation(componentPath); +} + + +//******** + + +static void opShowStatePath(Strings opFlags, Strings opArgs) +{ + Derivation drv = getDerivation_oneArgumentNoFlags(opFlags, opArgs); + DerivationStateOutputs stateOutputs = drv.stateOutputs; + Path statePath = stateOutputs.find("state")->second.statepath; + printMsg(lvlError, format("%1%") % statePath); +} + + +static void opShowStateReposRootPath(Strings opFlags, Strings opArgs) +{ + Derivation drv = getDerivation_oneArgumentNoFlags(opFlags, opArgs); + DerivationStateOutputs stateOutputs = drv.stateOutputs; + Path statePath = stateOutputs.find("state")->second.statepath; + + string drvName = drv.env.find("name")->second; + string stateIdentifier = stateOutputs.find("state")->second.stateIdentifier; + + //Get the a repository for this state location + string repos = makeStateReposPath("stateOutput:staterepospath", statePath, "", drvName, stateIdentifier); //this is a copy from store-state.cc + repos = repos.substr(0, repos.length() - stateRootRepos.length()); + + printMsg(lvlError, format("%1%") % repos); +} -//Look up the references of all (runtime) dependencies that maintain have state static void opCommitReferencesClosure(Strings opFlags, Strings opArgs) { @@ -40,9 +79,21 @@ static void opCommitReferencesClosure(Strings opFlags, Strings opArgs) printMsg(lvlError, format("NIX-STATE: `%1%'") % *i); }*/ + //get the derivation of the current component + Derivation drv = getDerivation_oneArgumentNoFlags(opFlags, opArgs); + DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs; + DerivationStateOutputs stateOutputs = drv.stateOutputs; + DerivationOutputs outputs = drv.outputs; + string drvName = drv.env.find("name")->second; + string stateIdentifier = stateOutputs.find("state")->second.stateIdentifier; + + + string path = *opArgs.begin(); + //Data from user / profile - string component = "/nix/store/s0g22b5lw693cjpclypkzan27d11v5pg-hellohardcodedstateworld-1.0"; + string component = path; //TODO Parse Path componentPath = component; //TODO call coerce function + string identifier = "test"; string binary = "hello"; @@ -53,45 +104,53 @@ static void opCommitReferencesClosure(Strings opFlags, Strings opArgs) //********************* Commit state ********************* - //get the derivation of the current component - Derivation drv = store->getStateDerivation(componentPath); - DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs; - DerivationStateOutputs stateOutputs = drv.stateOutputs; - DerivationOutputs outputs = drv.outputs; - string drvName = drv.env.find("name")->second; - string stateIdentifier = stateOutputs.find("state")->second.stateIdentifier; - - //get dependecies (if neccecary) of all state components that need to be updated PathSet paths = store->getStateReferencesClosure(componentPath); //get their derivations //... - //Get and update the intervals - //store->getStatePathsInterval(a); - //store->setStatePathsInterval(a); - //call the bash script on all the the store-state components + + + //******************* Call the commit script (recursively) + + //for(...){ + // + //} + string svnbin = nixSVNPath + "/svn"; string svnadminbin = nixSVNPath + "/svnadmin"; - Path statePath = stateOutputs.find("state")->second.statepath; - string stateDir = statePath; - + //Vector includeing all commit scripts: - vector commitscript; vector subversionedpaths; - vector subversionedpathsInterval; + vector subversionedpathsCommitBoolean; vector nonversionedpaths; //of type none, no versioning needed vector checkoutcommands; + //Get all the inverals from the database at once + PathSet intervalPaths; for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){ DerivationStateOutputDir d = i->second; string thisdir = d.path; - string fullstatedir = stateDir + "/" + thisdir; + string fullstatedir = statePath + "/" + thisdir; + Path statePath = fullstatedir; //TODO call coerce function + + if(d.type == "interval"){ + intervalPaths.insert(statePath); + } + } + vector intervals = store->getStatePathsInterval(intervalPaths); + + int intervalAt=0; + for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){ + DerivationStateOutputDir d = i->second; + + string thisdir = d.path; + string fullstatedir = statePath + "/" + thisdir; Path statePath = fullstatedir; //TODO call coerce function if(d.type == "none"){ @@ -100,64 +159,69 @@ static void opCommitReferencesClosure(Strings opFlags, Strings opArgs) } //Get the a repository for this state location - string repos = makeStateReposPath("stateOutput:staterepospath", stateDir, thisdir, drvName, stateIdentifier); //this is a copy from store-state.cc + string repos = makeStateReposPath("stateOutput:staterepospath", statePath, thisdir, drvName, stateIdentifier); //this is a copy from store-state.cc // checkoutcommands.push_back(svnbin + " checkout file://" + repos + " " + fullstatedir); subversionedpaths.push_back(fullstatedir); if(d.type == "interval"){ - subversionedpathsInterval.push_back(d.getInterval()); + + //TODO comment + + //Get the interval-counter from the database, and update it. + //printMsg(lvlError, format("Interval: %1% - %2%") % % ); + + int interval_counter = intervals[intervalAt]; + int interval = d.getInterval(); + + subversionedpathsCommitBoolean.push_back(interval_counter % interval == 0); + + //update the interval + intervals[intervalAt] = interval_counter + 1; + + intervalAt++; } + else if(d.type == "full") + subversionedpathsCommitBoolean.push_back(true); + else if(d.type == "manual") //TODO !!!!! + subversionedpathsCommitBoolean.push_back(false); else - subversionedpathsInterval.push_back(0); + throw Error(format("interval '%1%' is not handled in nix-state") % d.type); } + + //Update the intervals again + //store->setStatePathsInterval(intervalPaths, intervals); //TODO - //create super commit script - printMsg(lvlError, format("svnbin=%1%") % svnbin); - string subversionedstatepathsarray = "subversionedpaths=( "; + //Call the commit script with the appropiate paramenters + string subversionedstatepathsarray; for (vector::iterator i = subversionedpaths.begin(); i != subversionedpaths.end(); ++i) { subversionedstatepathsarray += *(i) + " "; } - printMsg(lvlError, format("%1%)") % subversionedstatepathsarray); - string subversionedpathsIntervalsarray = "subversionedpathsInterval=( "; - for (vector::iterator i = subversionedpathsInterval.begin(); i != subversionedpathsInterval.end(); ++i) + string subversionedpathsCommitBooleansarray; + for (vector::iterator i = subversionedpathsCommitBoolean.begin(); i != subversionedpathsCommitBoolean.end(); ++i) { - subversionedpathsIntervalsarray += int2String(*i) + " "; + subversionedpathsCommitBooleansarray += bool2string(*i) + " "; } - printMsg(lvlError, format("%1%)") % subversionedpathsIntervalsarray); - string nonversionedstatepathsarray = "nonversionedpaths=( "; + string nonversionedstatepathsarray; for (vector::iterator i = nonversionedpaths.begin(); i != nonversionedpaths.end(); ++i) { nonversionedstatepathsarray += *(i) + " "; } - printMsg(lvlError, format("%1%)") % nonversionedstatepathsarray); - string commandsarray = "checkouts=( "; + string commandsarray; for (vector::iterator i = checkoutcommands.begin(); i != checkoutcommands.end(); ++i) { - commandsarray += "\"" + *(i) + "\" "; + commandsarray += "\\\"" + *(i) + "\\\" "; } - printMsg(lvlError, format("%1%)") % commandsarray); - for (vector::iterator i = commitscript.begin(); i != commitscript.end(); ++i) - { - string s = *(i); - printMsg(lvlError, format("%1%") % s); - } - - - - //svnbin=/nix/var/nix/profiles/per-user/root/profile/bin/svn - //subversionedpaths=( /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/ ) - //subversionedpathsInterval=( 0 0 ) - //nonversionedpaths=( /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/cache/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/test/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/test2/test2/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/logging/ ) - //checkouts=( "/nix/var/nix/profiles/per-user/root/profile/bin/svn checkout file:///nix/staterepos/99dj5zg1ginj5as75nkb0psnp02krv2s-hellohardcodedstateworld-1.0 /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/" "/nix/var/nix/profiles/per-user/root/profile/bin/svn checkout file:///nix/staterepos/9ph3nd4irpvgs66h24xjvxrwpnrwy9n0-hellohardcodedstateworld-1.0 /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/" ) - - - //for(...){ - // - //} - + + //make the call + executeAndPrintShellCommand(nixLibexecDir + "/nix/nix-statecommit.sh " + svnbin + + " \"" + subversionedstatepathsarray + "\" " + + " \"" + subversionedpathsCommitBooleansarray + "\" " + + " \"" + nonversionedstatepathsarray + "\" " + + " \"" + commandsarray + "\" ", + "commit-script"); } @@ -173,27 +237,18 @@ void run(Strings args) if (arg == "--run" || arg == "-r") op = opCommitReferencesClosure; + else if (arg == "--showstatepath") + op = opShowStatePath; + else if (arg == "--showstatereposrootpath") + op = opShowStateReposRootPath; /* - --commit --run-without-commit --backup - - --showlocation - - - else if (arg == "--add" || arg == "-A") - op = opAdd; - else if (arg == "--add-fixed") - op = opAddFixed; - else if (arg == "--print-fixed-path") - op = opPrintFixedPath; - else if (arg[0] == '-') - opFlags.push_back(arg); */ else diff --git a/src/nix-state/statecommit.sh b/src/nix-state/statecommit.sh new file mode 100755 index 000000000..e9f4d337b --- /dev/null +++ b/src/nix-state/statecommit.sh @@ -0,0 +1,80 @@ +#! /bin/sh + +#TODO EXCLUDE PATHS AND MAKE PARAMETERS AND STORE OBJECT! +#check if all needed ... exists, if not, exit with an error + +svnbin=/nix/var/nix/profiles/per-user/root/profile/bin/svn +subversionedpaths=( /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/ ) +subversionedpathsInterval=( 0 0 ) +nonversionedpaths=( /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/cache/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/test/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/test2/test2/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/logging/ ) +checkouts=( "/nix/var/nix/profiles/per-user/root/profile/bin/svn checkout file:///nix/staterepos/99dj5zg1ginj5as75nkb0psnp02krv2s-hellohardcodedstateworld-1.0 /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/" "/nix/var/nix/profiles/per-user/root/profile/bin/svn checkout file:///nix/staterepos/9ph3nd4irpvgs66h24xjvxrwpnrwy9n0-hellohardcodedstateworld-1.0 /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/" ) + +# if a dir exists, get his rev. number or check it out again (maybe the dir was deleted) + +i=0 +for path in ${subversionedpaths[@]} +do + if test -d $path; then + cd $path; + output=$($svnbin stat 2>&1 | grep "is not a working copy"); + if [ "$output" != "" ] ; then #if the dir exists but is not yet an svn dir: create repos, if it doenst exits (is removed or something) than we dont do anything + ${checkouts[$i]}; + + repos=$(svn info | grep "Repository Root" | sed 's/Repository Root: //'); # get the revision number of the repository + revision=$(svn info $repos | grep "Revision: " | sed 's/Revision: //'); + interval=${subversionedpathsInterval[$i]}; + + #TODO BUG !!!!!!!! THE REVISION DOESNT GO UP WE NEED A DB CONNECTION OR A FILE TO HOLD A COUNTER ...! + + if [ "$interval" = "0" ] || [ "$($revision % $interval)" = "0" ]; then # if we dont have an interval or the interval is due... commit + + allsubdirs=( $(echo *) ); + subdirs=(); + for subdir in ${allsubdirs[@]} #add all, exlucding explicity stated direct versioned-subdirs or explicity stated nonversioned-subdirs + do #this is only to prevent some warnings, ultimately we would like svn add to have a option 'exclude dirs' + subdir="$(pwd)/$subdir/"; + exclude=0; + + for svnp in ${subversionedpaths[@]} #check if the subdir is in the list of subverioned paths + do + if [ "$svnp" = "$subdir" ]; then + exclude=1; + fi + done + + for nonvp in ${nonversionedpaths[@]} #check if the subdir is in the list of dirs that aren't supposed to be versioned + do + if [ "$nonvp" = "$subdir" ]; then + exclude=1; + fi + done + + if [ $exclude = 0 ]; then #If it is ... that we exclude the subdir + subdirs[${#subdirs[*]}]=$subdir + fi + done + + if [ "$subdirs" != "" ]; then + svn add $subdirs; #add all subdirs + + for revpath in ${nonversionedpaths[@]} #We need to revert sub-sub* dirs, since these havent been excluded + do + if test -d $revpath; then + if [ "${revpath:0:${#path}}" == "$path" ]; then + #echo "$path revert $revpath"; + svn revert $revpath; + fi + fi + done + + svn -m "" commit; #Finally, we commit + fi + + fi + fi + + cd - &> /dev/null; + fi + let "i+=1" +done + diff --git a/src/nix-state/statecommitTMP.sh b/src/nix-state/statecommitTMP.sh deleted file mode 100755 index a0bffe8be..000000000 --- a/src/nix-state/statecommitTMP.sh +++ /dev/null @@ -1,78 +0,0 @@ -#! /bin/sh - -#TODO EXCLUDE PATHS AND MAKE PARAMETERS AND STORE OBJECT! - -svnbin=/nix/var/nix/profiles/per-user/root/profile/bin/svn -subversionedpaths=( /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/ ) -subversionedpathsInterval=( 0 0 ) -nonversionedpaths=( /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/cache/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/test/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/test2/test2/ /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/logging/ ) -checkouts=( "/nix/var/nix/profiles/per-user/root/profile/bin/svn checkout file:///nix/staterepos/99dj5zg1ginj5as75nkb0psnp02krv2s-hellohardcodedstateworld-1.0 /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/" "/nix/var/nix/profiles/per-user/root/profile/bin/svn checkout file:///nix/staterepos/9ph3nd4irpvgs66h24xjvxrwpnrwy9n0-hellohardcodedstateworld-1.0 /nix/state/v6rr3yi5ilgn3k0kwxkk633ap4z0m1zi-hellohardcodedstateworld-1.0/log/" ) - -# if a dir exists, get his rev. number or check it out again (maybe the dir was deleted) - -i=0 -for path in ${subversionedpaths[@]} -do - if test -d $path; then - cd $path; - output=$($svnbin stat 2>&1 | grep "is not a working copy"); - if [ "$output" != "" ] ; then #if dirs exists but is not yet an svn dir: create repos - ${checkouts[$i]}; - fi - - repos=$(svn info | grep "Repository Root" | sed 's/Repository Root: //'); # get the revision number of the repository - revision=$(svn info $repos | grep "Revision: " | sed 's/Revision: //'); - interval=${subversionedpathsInterval[$i]}; - - #TODO BUG !!!!!!!! THE REVISION DOESNT GO UP WE NEED A DB CONNECTION OR A FILE TO HOLD A COUNTER ...! - - if [ "$interval" = "0" ] || [ "$($revision % $interval)" = "0" ]; then # if we dont have an interval or the interval is due... commit - - allsubdirs=( $(echo *) ); - subdirs=(); - for subdir in ${allsubdirs[@]} #add all, exlucding explicity stated direct versioned-subdirs or explicity stated nonversioned-subdirs - do #this is only to prevent some warnings, ultimately we would like svn add to have a option 'exclude dirs' - subdir="$(pwd)/$subdir/"; - exclude=0; - - for svnp in ${subversionedpaths[@]} - do - if [ "$svnp" = "$subdir" ]; then - exclude=1; - fi - done - - for nonvp in ${nonversionedpaths[@]} - do - if [ "$nonvp" = "$subdir" ]; then - exclude=1; - fi - done - - if [ $exclude = 0 ]; then - subdirs[${#subdirs[*]}]=$subdir - fi - done - - if [ "$subdirs" != "" ]; then - svn add $subdirs; - - for revpath in ${nonversionedpaths[@]} #revert sub-sub* dirs that havent been excluded - do - if test -d $revpath; then - if [ "${revpath:0:${#path}}" == "$path" ]; then - #echo "$path revert $revpath"; - svn revert $revpath; - fi - fi - done - svn -m "" commit; - fi - - fi - - cd - &> /dev/null; - fi - let "i+=1" -done -