mirror of
https://github.com/NixOS/nix
synced 2025-07-02 01:01:48 +02:00
Implement tests for lookupPathForProgram and fix bugs caught by tests
This commit is contained in:
parent
d7537f6955
commit
4f6e3b9402
2 changed files with 13 additions and 5 deletions
|
@ -94,7 +94,7 @@ std::string runProgram(
|
|||
Path lookupPathForProgram(const Path & program)
|
||||
{
|
||||
if (program.find('/') != program.npos || program.find('\\') != program.npos) {
|
||||
throw Error("program '%1%' partially specifies its path", program);
|
||||
throw UsageError("program '%1%' partially specifies its path", program);
|
||||
}
|
||||
|
||||
// Possible extensions.
|
||||
|
@ -107,8 +107,9 @@ Path lookupPathForProgram(const Path & program)
|
|||
}
|
||||
|
||||
// Look through each directory listed in $PATH.
|
||||
for (const std::string & dir : tokenizeString<Strings>(*getEnv("PATH"), ";")) {
|
||||
Path candidate = canonPath(dir) + '/' + program;
|
||||
for (const std::string & dir : tokenizeString<Strings>(*path, ";")) {
|
||||
// TODO: This should actually be canonPath(dir), but that ends up appending two drive paths
|
||||
Path candidate = dir + "/" + program;
|
||||
for (const auto ext : exts) {
|
||||
if (pathExists(candidate + ext)) {
|
||||
return candidate;
|
||||
|
@ -408,5 +409,4 @@ bool statusOk(int status)
|
|||
{
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue