From 86f0fd83419a1907e1d5e82f01d3fb18cf5fcd79 Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Wed, 19 Sep 2007 22:00:43 +0000 Subject: [PATCH] Fixed ~ and * to expand in cp and ln commands. --- src/libutil/util.cc | 45 +++++++++++++++++++++++++++++++++++------- src/nix-env/nix-env.cc | 3 ++- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 9d64f6412..38bc7f1ca 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1281,17 +1281,23 @@ string padd(const string & s, char c , unsigned int size, bool front) return ss; } -void symlinkPath(const Path & existingDir, const Path & newLinkName) +void symlinkPath(const Path & existingDir, const Path & newLinkName) //TODO bool shellexpansion { //Symlink link to the share path //Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) 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("ln", true, p_args, "ln"); + */ + runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-ln"); - //printMsg(lvlError, format("ln -sf %1% %2%") % existingDir % newLinkName); + executeShellCommand("whoami"); + executeShellCommand("pwd"); + printMsg(lvlError, format("ln -sf %1% %2%") % existingDir % newLinkName); } void removeSymlink(const string & path) @@ -1308,20 +1314,45 @@ void ensureStateDir(const Path & statePath, const string & user, const string & setChmod(statePath, chmod); } -void copyContents(const Path & from, const Path & to) +void copyContents(const Path & from, const Path & to) //TODO bool shellexpansion, bool failure for nix-env { + //executeShellCommand("whoami"); + + //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); + */ + + //executeShellCommand("ls -l "+from); + //executeShellCommand("ls -l "+from+"/"); + //executeShellCommand("ls -l "+to); + //executeShellCommand("ls -l "+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); + /* + p_args.push_back("cp"); p_args.push_back("-R"); p_args.push_back(from + "/*"); p_args.push_back(to); - runProgram_AndPrintOutput("cp", true, p_args, "cp"); + */ + runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-cp"); //Also copy the hidden files (but not the ../ dir) - p_args.clear(); + p_args.empty(); + p_args.push_back("-c"); + p_args.push_back("cp " + from + "/.[a-zA-Z0-9]* " +to); + /* + p_args.push_back(cp"); p_args.push_back(from + "/.[a-zA-Z0-9]*"); p_args.push_back(to); - runProgram_AndPrintOutput("cp", true, p_args, "cp"); + */ + runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-cp"); } } diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 820a5a01e..cde585980 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -639,7 +639,7 @@ static void installDerivations(Globals & globals, PathSet comparePaths; comparePaths.insert(statePath); comparePaths.insert(read_statePath); - if(store->toNonSharedPathSet(comparePaths).size() != 1) + if(store->toNonSharedPathSet(comparePaths).size() != 1) //TODO !!!!!!!!!!!!! only copy when not already a symlink to a statePath !!!!!!!!! copyContents(externalState, statePath); } else @@ -659,6 +659,7 @@ static void installDerivations(Globals & globals, //Now we create a symlink externalState --> statePath printMsg(lvlError, format("SYMLINK: '%1%' --> '%2%'") % externalState % statePath); + executeShellCommand("whoami"); symlinkPath(statePath, externalState); }