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

before changing db schema

This commit is contained in:
Wouter den Breejen 2007-05-25 12:27:36 +00:00
parent c9e78a973a
commit 0a303ea2c0
9 changed files with 402 additions and 1 deletions

View file

@ -278,6 +278,7 @@ AC_CONFIG_FILES([Makefile
src/libstore/Makefile src/libstore/Makefile
src/libmain/Makefile src/libmain/Makefile
src/nix-store/Makefile src/nix-store/Makefile
src/nix-state/Makefile
src/nix-hash/Makefile src/nix-hash/Makefile
src/libexpr/Makefile src/libexpr/Makefile
src/nix-instantiate/Makefile src/nix-instantiate/Makefile

View file

@ -1377,7 +1377,6 @@ void DerivationGoal::startBuilder()
tmpDir = createTempDir(); tmpDir = createTempDir();
/* Create the state directory where the component can store it's state files place */ /* Create the state directory where the component can store it's state files place */
//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 //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.size() != 0)
if(drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall()) if(drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall())

View file

@ -72,6 +72,14 @@ static TableId dbSubstitutes = 0;
static TableId dbDerivers = 0; static TableId dbDerivers = 0;
/* dbStateCounters :: StatePath -> Int
This table lists the state folders that state managed components
and are of type interval.
*/
static TableId dbStateCounters = 0;
bool Substitute::operator == (const Substitute & sub) const bool Substitute::operator == (const Substitute & sub) const
{ {
return program == sub.program return program == sub.program
@ -352,6 +360,9 @@ void queryReferences(const Transaction & txn,
const Path & storePath, PathSet & references) const Path & storePath, PathSet & references)
{ {
Paths references2; Paths references2;
//WOUTER EDIT
if (!isRealisablePath(txn, storePath)) if (!isRealisablePath(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath); throw Error(format("path `%1%' is not valid") % storePath);
nixDB.queryStrings(txn, dbReferences, storePath, references2); nixDB.queryStrings(txn, dbReferences, storePath, references2);

14
src/nix-state/Makefile.am Normal file
View file

@ -0,0 +1,14 @@
bin_PROGRAMS = nix-state
nix_state_SOURCES = nix-state.cc help.txt
nix_state_LDADD = ../libmain/libmain.la ../libstore/libstore.la ../libutil/libutil.la \
../boost/format/libformat.la ${bdb_lib} ${aterm_lib}
nix-state.o: help.txt.hh
%.txt.hh: %.txt
../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1)
AM_CXXFLAGS = \
-I$(srcdir)/.. ${bdb_include} $(aterm_include) -I$(srcdir)/../libutil \
-I$(srcdir)/../libstore -I$(srcdir)/../libmain

58
src/nix-state/help.txt Normal file
View file

@ -0,0 +1,58 @@
Usage: nix-state [OPTIONS...] [ARGUMENTS...]
`nix-store' is a tool to manipulate the Nix store.
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
--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

File diff suppressed because one or more lines are too long

117
src/nix-state/nix-state Executable file
View file

@ -0,0 +1,117 @@
#! /bin/sh
# nix-state - temporary wrapper script for .libs/nix-state
# Generated by ltmain.sh - GNU libtool 1.5.22 (1.1220.2.365 2005/12/18 22:14:06)
#
# The nix-state program cannot be directly executed until all the libtool
# libraries that it depends on are installed.
#
# This wrapper script should never be moved out of the build directory.
# If it is, it will not operate correctly.
# Sed substitution that helps us do robust quoting. It backslashifies
# metacharacters that are still active within double-quoted strings.
Xsed='/nix/var/nix/profiles/per-user/root/profile/bin/sed -e 1s/^X//'
sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
# The HP-UX ksh and POSIX shell print the target directory to stdout
# if CDPATH is set.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
relink_command="(cd /root/dev/nix-state/src/nix-state; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=\"/root/bin:/nix/var/nix/profiles/per-user/root/profile/bin:/nix/var/nix/profiles/per-user/root/profile/sbin:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:/var/setuid-wrappers:/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin:/home/share/bin:/home/share/bin\"; export PATH; g++ -I./.. -I/root/.nix-profile/include -I/root/.nix-profile/include -I./../libutil -I./../libstore -I./../libmain -D_FILE_OFFSET_BITS=64 -g -O2 -o \$progdir/\$file nix-state.o ../libmain/.libs/libmain.so -L/tmp/nix-14177-0/build/i686-pc-linux-gnu/libstdc++-v3/src -L/tmp/nix-14177-0/build/i686-pc-linux-gnu/libstdc++-v3/src/.libs ../libstore/.libs/libstore.so /root/dev/nix-state/src/libutil/.libs/libutil.so ../libutil/.libs/libutil.so /root/dev/nix-state/src/boost/format/.libs/libformat.so ../boost/format/.libs/libformat.so /nix/store/kpqz9a4clx96538rr0zmsy3v40iqd88g-gcc-4.1.1/lib/libstdc++.so -L/root/.nix-profile/lib -ldb_cxx /nix/store/pkmzbb613wa8cwngx8jjb5jaic8yhyzs-aterm-2.4.2-fixes/lib/libATerm -lpthread -Wl,--rpath -Wl,/root/dev/nix-state/src/libmain/.libs -Wl,--rpath -Wl,/root/dev/nix-state/src/libstore/.libs -Wl,--rpath -Wl,/root/dev/nix-state/src/libutil/.libs -Wl,--rpath -Wl,/root/dev/nix-state/src/boost/format/.libs -Wl,--rpath -Wl,/nix/store/kpqz9a4clx96538rr0zmsy3v40iqd88g-gcc-4.1.1/lib -Wl,--rpath -Wl,/nix/store/pkmzbb613wa8cwngx8jjb5jaic8yhyzs-aterm-2.4.2-fixes/lib -Wl,--rpath -Wl,/nixstate/nix/lib/nix -Wl,--rpath -Wl,/nix/store/kpqz9a4clx96538rr0zmsy3v40iqd88g-gcc-4.1.1/lib -Wl,--rpath -Wl,/nix/store/pkmzbb613wa8cwngx8jjb5jaic8yhyzs-aterm-2.4.2-fixes/lib)"
# This environment variable determines our operation mode.
if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
# install mode needs the following variable:
notinst_deplibs=' ../libmain/libmain.la ../libstore/libstore.la /root/dev/nix-state/src/libutil/libutil.la ../libutil/libutil.la /root/dev/nix-state/src/boost/format/libformat.la ../boost/format/libformat.la'
else
# When we are sourced in execute mode, $file and $echo are already set.
if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
echo="echo"
file="$0"
# Make sure echo works.
if test "X$1" = X--no-reexec; then
# Discard the --no-reexec flag, and continue.
shift
elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then
# Yippee, $echo works!
:
else
# Restart under the correct shell, and then maybe $echo will work.
exec /bin/sh "$0" --no-reexec ${1+"$@"}
fi
fi
# Find the directory that this script lives in.
thisdir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
test "x$thisdir" = "x$file" && thisdir=.
# Follow symbolic links until we get to the real thisdir.
file=`ls -ld "$file" | /nix/var/nix/profiles/per-user/root/profile/bin/sed -n 's/.*-> //p'`
while test -n "$file"; do
destdir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
# If there was a directory component, then change thisdir.
if test "x$destdir" != "x$file"; then
case "$destdir" in
[\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
*) thisdir="$thisdir/$destdir" ;;
esac
fi
file=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
file=`ls -ld "$thisdir/$file" | /nix/var/nix/profiles/per-user/root/profile/bin/sed -n 's/.*-> //p'`
done
# Try to get the absolute directory name.
absdir=`cd "$thisdir" && pwd`
test -n "$absdir" && thisdir="$absdir"
program=lt-'nix-state'
progdir="$thisdir/.libs"
if test ! -f "$progdir/$program" || \
{ file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /nix/var/nix/profiles/per-user/root/profile/bin/sed 1q`; \
test "X$file" != "X$progdir/$program"; }; then
file="$$-$program"
if test ! -d "$progdir"; then
mkdir "$progdir"
else
rm -f "$progdir/$file"
fi
# relink executable if necessary
if test -n "$relink_command"; then
if relink_command_output=`eval $relink_command 2>&1`; then :
else
echo "$relink_command_output" >&2
rm -f "$progdir/$file"
exit 1
fi
fi
mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null ||
{ rm -f "$progdir/$program";
mv -f "$progdir/$file" "$progdir/$program"; }
rm -f "$progdir/$file"
fi
if test -f "$progdir/$program"; then
if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
# Run the actual program with our arguments.
exec "$progdir/$program" ${1+"$@"}
$echo "$0: cannot exec $program ${1+"$@"}"
exit 1
fi
else
# The program doesn't exist.
$echo "$0: error: \`$progdir/$program' does not exist" 1>&2
$echo "This script is just a wrapper for $program." 1>&2
echo "See the libtool documentation for more information." 1>&2
exit 1
fi
fi

122
src/nix-state/nix-state.cc Normal file
View file

@ -0,0 +1,122 @@
#include <iostream>
#include <algorithm>
#include "globals.hh"
#include "misc.hh"
#include "archive.hh"
#include "shared.hh"
#include "db.hh"
#include "util.hh"
#include "help.txt.hh"
using namespace nix;
using std::cin;
using std::cout;
typedef void (* Operation) (Strings opFlags, Strings opArgs);
void printHelp()
{
cout << string((char *) helpText, sizeof helpText);
}
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(){
Database nixDB;
try {
nixDB.open(nixDBPath);
} catch (DbNoPermission & e) {
printMsg(lvlTalkative, "cannot access Nix database; continuing anyway");
//readOnlyMode = true;
return;
}
Paths referencesKeys;
Transaction txn(nixDB);
TableId dbReferences = nixDB.openTable("references");
nixDB.enumTable(txn, dbReferences, referencesKeys);
for (Paths::iterator i = referencesKeys.begin(); i != referencesKeys.end(); ++i)
{
printMsg(lvlError, format("NIX-STATE: `%1%'") % *i);
}
/*
Transaction txn;
createStoreTransaction(txn);
for (DerivationOutputs::iterator i = drv.outputs.begin();
i != drv.outputs.end(); ++i)
{
registerValidPath(txn, i->second.path,
contentHashes[i->second.path],
allReferences[i->second.path],
drvPath);
}
txn.commit();
*/
}
//Call the appropiate commit scripts with variables like interval
/* 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;
Operation op = 0;
for (Strings::iterator i = args.begin(); i != args.end(); ) {
string arg = *i++;
Operation oldOp = op;
/*
if (arg == "--realise" || arg == "-r")
op = opRealise;
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
opArgs.push_back(arg);
if (oldOp && oldOp != op)
throw UsageError("only one operation may be specified");
*/
}
commitReferencesClosure();
//if (!op) throw UsageError("no operation specified");
//op(opFlags, opArgs);
}
string programId = "nix-state";

78
src/nix-state/statecommitTMP.sh Executable file
View file

@ -0,0 +1,78 @@
#! /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