mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 04:00:59 +01:00
Replaced cp for rsync to copy state
This commit is contained in:
parent
d0458acb7c
commit
43d93e5e64
12 changed files with 53 additions and 45 deletions
|
|
@ -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=)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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\" \
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ namespace nix {
|
|||
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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include "db.hh"
|
||||
#include "util.hh"
|
||||
#include "local-store.hh"
|
||||
#include "store-state.hh"
|
||||
|
||||
#include <cerrno>
|
||||
#include <ctime>
|
||||
|
|
|
|||
|
|
@ -569,11 +569,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 */
|
||||
|
||||
if(args.size() == 1 && ( *(args.begin()) == "--help" || *(args.begin()) == "--statehelp")){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue