From 43d93e5e64906cf41d381d1d22725912752f5a23 Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Wed, 3 Oct 2007 09:46:22 +0000 Subject: [PATCH] Replaced cp for rsync to copy state --- configure.ac | 8 +++++++- install_full.sh | 4 +--- src/libmain/Makefile.am | 1 + src/libmain/shared.cc | 1 + src/libstore/globals.cc | 1 + src/libstore/globals.hh | 3 +++ src/libstore/store-state.cc | 32 +++++++++++++++++++++++++++++++- src/libstore/store-state.hh | 4 +++- src/libutil/util.cc | 35 +---------------------------------- src/libutil/util.hh | 3 --- src/nix-env/nix-env.cc | 1 + src/nix-state/nix-state.cc | 5 +++-- 12 files changed, 53 insertions(+), 45 deletions(-) diff --git a/configure.ac b/configure.ac index 048229cd8..b72b47f00 100644 --- a/configure.ac +++ b/configure.ac @@ -184,11 +184,17 @@ AC_SUBST(bdb_lib) AC_SUBST(bdb_include) AC_ARG_WITH(ext3cow-header, AC_HELP_STRING([--with-ext3cow-header=PATH], - [path of the header ext3cow header ext3cow_fs.h]), + [path of the ext3cow header ext3cow_fs.h]), ext3cowheader=$withval, ext3cowheader=) AC_SUBST(ext3cowheader) AC_CHECK_HEADER(${ext3cowheader}) +NEED_PROG(rsync, rsync) +AC_ARG_WITH(rsync, AC_HELP_STRING([--with-rsync=PATH], + [path to the rsync binary.]), + rsync=$withval) +AC_SUBST(rsync) + AC_ARG_WITH(aterm, AC_HELP_STRING([--with-aterm=PATH], [prefix of CWI ATerm library]), aterm=$withval, aterm=) diff --git a/install_full.sh b/install_full.sh index e51a96a5d..f27f9d677 100755 --- a/install_full.sh +++ b/install_full.sh @@ -23,7 +23,7 @@ if [ "$1" = "full" ]; then nix-env-all-pkgs.sh -i gnumake nix-env-all-pkgs.sh -i ext3cow-tools nix-env-all-pkgs.sh -i e3cfsprogs - + nix-env-all-pkgs.sh -i rsync fi if [ "$1" = "full" ] || [ "$1" = "auto" ]; then @@ -51,8 +51,6 @@ fi --with-ext3cow-header=/nix/store/v95qf520d6972pshykrah1dz3z53rkmj-linux-2.6.21.7/lib/modules/2.6.21.7-default/build/include/linux/ext3cow_fs.h \ --localstatedir=/nix/var - - #Options from the nix expr #--disable-init-state #--with-store-dir=/nix/store diff --git a/src/libmain/Makefile.am b/src/libmain/Makefile.am index 2effd36c4..9382d81e3 100644 --- a/src/libmain/Makefile.am +++ b/src/libmain/Makefile.am @@ -6,6 +6,7 @@ AM_CXXFLAGS = \ -DNIX_STORE_DIR=\"$(storedir)\" \ -DNIX_STORE_STATE_DIR=\"$(storestatedir)\" \ -DNIX_EXT3_COW_HEADER=\"$(ext3cowheader)\" \ + -DNIX_RSYNC=\"$(rsync)\" \ -DNIX_DATA_DIR=\"$(datadir)\" \ -DNIX_STATE_DIR=\"$(localstatedir)/nix\" \ -DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \ diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 2a53f7c48..9d149a8a1 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -93,6 +93,7 @@ static void initAndRun(int argc, char * * argv) nixStateDir = canonPath(getEnv("NIX_STATE_DIR", NIX_STATE_DIR)); //nix global state dir nixDBPath = getEnv("NIX_DB_DIR", nixStateDir + "/db"); nixExt3CowHeader = getEnv("NIX_EXT3_COW_HEADER", NIX_EXT3_COW_HEADER); + nixRsync = getEnv("NIX_RSYNC", NIX_RSYNC); nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR)); nixLibexecDir = canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR)); nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR)); diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 3070e8637..d0285676f 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -15,6 +15,7 @@ string nixLogDir = "/UNINIT"; string nixStateDir = "/UNINIT"; string nixDBPath = "/UNINIT"; string nixExt3CowHeader = "/UNINIT"; +string nixRsync = "/UNINIT"; string nixConfDir = "/UNINIT"; string nixLibexecDir = "/UNINIT"; string nixBinDir = "/UNINIT"; diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index 3e1f70916..0846f4e07 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -30,6 +30,9 @@ extern string nixDBPath; /* nixExt3CowHeader is the header file used to communicate with ext3cow. */ extern string nixExt3CowHeader; +/* nixRsync is used to copy from one statedir to the other. */ +extern string nixRsync; + /* nixConfDir is the directory where configuration files are stored. */ extern string nixConfDir; diff --git a/src/libstore/store-state.cc b/src/libstore/store-state.cc index 06fbca93a..769d44091 100644 --- a/src/libstore/store-state.cc +++ b/src/libstore/store-state.cc @@ -108,7 +108,7 @@ void revertToRevisionTxn(const Transaction & txn, const Path & statePath, const RevisionClosureTS getTimestamps; queryStateRevisionsTxn(txn, statePath_ns, getRivisions, getTimestamps, revision_arg); - //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //include recursive //lookup 0 (latest) to the real revision @@ -714,4 +714,34 @@ bool queryAvailableStateRevisions(Database & nixDB, const Transaction & txn, Tab return true; } +void copyContents(const Path & from, const Path & to) //TODO bool shellexpansion, bool failure for nix-env +{ + //TODO Could be a symlink (to a non-existing dir) + /* + if(!DirectoryExist(from)) + throw Error(format("Path `%1%' doenst exist ...") % from); + if(!DirectoryExist(to)) + throw Error(format("Path `%1%' doenst exist ...") % to); + */ + + //We add a slash / to the end to ensure the contents is copyed + Path from2 = from; + Path to2 = to; + if(from2[from2.length() - 1] != '/') + from2 = from2 + "/"; + if(to2[to2.length() - 1] != '/') + to2 = to2 + "/"; + + printMsg(lvlError, format("Rsync from: '%1%' to: '%2%'") % from2 % to2); + + //Rsync from --> to and also with '-avHx --delete' + //This makes the paths completely equal (also deletes) and retains times ownership etc. + Strings p_args; + p_args.push_back("-avHx"); + p_args.push_back("--delete"); + p_args.push_back(from2); + p_args.push_back(to2); + runProgram_AndPrintOutput(nixRsync, true, p_args, "rsync"); +} + } diff --git a/src/libstore/store-state.hh b/src/libstore/store-state.hh index ea7a24afc..da02a430e 100644 --- a/src/libstore/store-state.hh +++ b/src/libstore/store-state.hh @@ -66,7 +66,9 @@ namespace nix { /* Returns all available revision numbers of the given state path */ bool queryAvailableStateRevisions(Database & nixDB, const Transaction & txn, TableId revisions_table, TableId revisions_comments, const Path & statePath, RevisionInfos & revisions); - + + /* Copy all files and folders recursively (also the hidden ones) from the dir from/... to the dir to/... and delete the rest in to/ (Rsync) */ + void copyContents(const Path & from, const Path & to); } diff --git a/src/libutil/util.cc b/src/libutil/util.cc index db9d7c000..07da64a23 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1288,15 +1288,7 @@ void symlinkPath(const Path & existingDir, const Path & newLinkName) //TODO bool Strings p_args; p_args.push_back("-c"); //we call the shell (/bin/sh -c) so it expands the ~ to a users home dir p_args.push_back("ln -sf " + existingDir + " " + newLinkName); - /* - p_args.push_back("-sf"); - p_args.push_back(existingDir); - p_args.push_back(newLinkName); - */ runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-ln"); - - //executeShellCommand("whoami"); - //executeShellCommand("pwd"); printMsg(lvlError, format("ln -sf %1% %2%") % existingDir % newLinkName); } @@ -1314,31 +1306,6 @@ void ensureStateDir(const Path & statePath, const string & user, const string & setChmod(statePath, chmod); } -void copyContents(const Path & from, const Path & to) //TODO bool shellexpansion, bool failure for nix-env -{ - //TODO Could be a symlink (to a non-existing dir) - /* - if(!DirectoryExist(from)) - throw Error(format("Path `%1%' doenst exist ...") % from); - if(!DirectoryExist(to)) - throw Error(format("Path `%1%' doenst exist ...") % to); - */ - - //TODO do a Rsync instead of a cp. - //rsync -avHx --delete from to - - //Copy all files + dirs recursively - Strings p_args; - p_args.push_back("-c"); //we call the shell (/bin/sh -c) so it expands the * to all files - p_args.push_back("cp -R "+from + "/* "+to); - runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-cp"); - - //Also copy the hidden files (but not the ../ dir) - p_args.empty(); - p_args.push_back("-c"); - p_args.push_back("cp " + from + "/.[a-zA-Z0-9]* " +to); - runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-cp"); - -} + } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 18eefae55..6073eb465 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -336,9 +336,6 @@ void removeSymlink(const string & path); void ensureStateDir(const Path & statePath, const string & user, const string & group, const string & chmod); -/* Copy all files and folders recursively (also the hidden ones) from the dir from/... to the dir to/... */ -void copyContents(const Path & from, const Path & to); - } #endif /* !__UTIL_H */ diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 8e4372ac3..d7966284b 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -16,6 +16,7 @@ #include "db.hh" #include "util.hh" #include "local-store.hh" +#include "store-state.hh" #include #include diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index 01ac81210..9f2bf6eed 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -568,11 +568,12 @@ void run(Strings args) deletePath("/nix/state/b"); copyContents("/nix/state/a", "/nix/state/b"); + + printMsg(lvlError, format("Rsync: '%1%'") % nixRsync); + copyContents("/nix/state/fwir6jlqygy90zadnx95zryfa8918qac-hellohardcodedstateworld-1.0-test/", "/home/wouterdb/tmp/aa/"); //TODO !!!!!!!!!!!!!!!!!!! return; - */ - /* test */