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

Fixed ~ and * to expand in cp and ln commands.

This commit is contained in:
Wouter den Breejen 2007-09-19 22:00:43 +00:00
parent 4c32f38047
commit 86f0fd8341
2 changed files with 40 additions and 8 deletions

View file

@ -1281,17 +1281,23 @@ string padd(const string & s, char c , unsigned int size, bool front)
return ss; 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 //Symlink link to the share path
//Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) //Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
Strings p_args; 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("-sf");
p_args.push_back(existingDir); p_args.push_back(existingDir);
p_args.push_back(newLinkName); 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) void removeSymlink(const string & path)
@ -1308,20 +1314,45 @@ void ensureStateDir(const Path & statePath, const string & user, const string &
setChmod(statePath, chmod); 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 //Copy all files + dirs recursively
Strings p_args; 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("-R");
p_args.push_back(from + "/*"); p_args.push_back(from + "/*");
p_args.push_back(to); 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) //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(from + "/.[a-zA-Z0-9]*");
p_args.push_back(to); p_args.push_back(to);
runProgram_AndPrintOutput("cp", true, p_args, "cp"); */
runProgram_AndPrintOutput("/bin/sh", true, p_args, "sh-cp");
} }
} }

View file

@ -639,7 +639,7 @@ static void installDerivations(Globals & globals,
PathSet comparePaths; PathSet comparePaths;
comparePaths.insert(statePath); comparePaths.insert(statePath);
comparePaths.insert(read_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); copyContents(externalState, statePath);
} }
else else
@ -659,6 +659,7 @@ static void installDerivations(Globals & globals,
//Now we create a symlink externalState --> statePath //Now we create a symlink externalState --> statePath
printMsg(lvlError, format("SYMLINK: '%1%' --> '%2%'") % externalState % statePath); printMsg(lvlError, format("SYMLINK: '%1%' --> '%2%'") % externalState % statePath);
executeShellCommand("whoami");
symlinkPath(statePath, externalState); symlinkPath(statePath, externalState);
} }