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

the command /nixstate/nix/bin/nix-state --run /nix/store/sig2qgvaayydrwy5hn6b2dm5r2ayhv5s-hellohardcodedstateworld-1.0 now causes state to be checked and comitted

This commit is contained in:
Wouter den Breejen 2007-05-30 17:16:25 +00:00
parent 653e557e81
commit 25117fd165
10 changed files with 378 additions and 202 deletions

View file

@ -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

92
scripts/nix-statecommit.sh.in Executable file
View file

@ -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

View file

@ -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;

View file

@ -1140,7 +1140,12 @@ vector<int> 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();

View file

@ -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
}
}

View file

@ -10,6 +10,8 @@
#include <cerrno>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <iostream>
#include <sys/stat.h>
#include <sys/wait.h>
@ -1008,4 +1010,59 @@ string trim(const string & 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
}
}

View file

@ -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);
}

View file

@ -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<string> commitscript;
vector<string> subversionedpaths;
vector<int> subversionedpathsInterval;
vector<bool> subversionedpathsCommitBoolean;
vector<string> nonversionedpaths; //of type none, no versioning needed
vector<string> 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<int> 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);
}
//create super commit script
printMsg(lvlError, format("svnbin=%1%") % svnbin);
string subversionedstatepathsarray = "subversionedpaths=( ";
//Update the intervals again
//store->setStatePathsInterval(intervalPaths, intervals); //TODO
//Call the commit script with the appropiate paramenters
string subversionedstatepathsarray;
for (vector<string>::iterator i = subversionedpaths.begin(); i != subversionedpaths.end(); ++i)
{
subversionedstatepathsarray += *(i) + " ";
}
printMsg(lvlError, format("%1%)") % subversionedstatepathsarray);
string subversionedpathsIntervalsarray = "subversionedpathsInterval=( ";
for (vector<int>::iterator i = subversionedpathsInterval.begin(); i != subversionedpathsInterval.end(); ++i)
string subversionedpathsCommitBooleansarray;
for (vector<bool>::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<string>::iterator i = nonversionedpaths.begin(); i != nonversionedpaths.end(); ++i)
{
nonversionedstatepathsarray += *(i) + " ";
}
printMsg(lvlError, format("%1%)") % nonversionedstatepathsarray);
string commandsarray = "checkouts=( ";
string commandsarray;
for (vector<string>::iterator i = checkoutcommands.begin(); i != checkoutcommands.end(); ++i)
{
commandsarray += "\"" + *(i) + "\" ";
}
printMsg(lvlError, format("%1%)") % commandsarray);
for (vector<string>::iterator i = commitscript.begin(); i != commitscript.end(); ++i)
{
string s = *(i);
printMsg(lvlError, format("%1%") % s);
commandsarray += "\\\"" + *(i) + "\\\" ";
}
//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

80
src/nix-state/statecommit.sh Executable file
View file

@ -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

View file

@ -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