nix-shell: Ignore readFile() errors

Fixes #1563.
This commit is contained in:
Eelco Dolstra 2017-09-18 13:28:00 +02:00
parent aca4f7dff0
commit 84f112b1c8
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -105,12 +105,12 @@ void mainWrapped(int argc, char * * argv)
for (int i = 1; i < argc; ++i) for (int i = 1; i < argc; ++i)
args.push_back(argv[i]); args.push_back(argv[i]);
// Heuristic to see if we're invoked as a shebang script, namely, if we // Heuristic to see if we're invoked as a shebang script, namely,
// have a single argument, it's the name of an executable file, and it // if we have at least one argument, it's the name of an
// starts with "#!". // executable file, and it starts with "#!".
if (runEnv && argc > 1 && !std::regex_search(argv[1], std::regex("nix-shell"))) { if (runEnv && argc > 1 && !std::regex_search(argv[1], std::regex("nix-shell"))) {
script = argv[1]; script = argv[1];
if (access(script.c_str(), F_OK) == 0 && access(script.c_str(), X_OK) == 0) { try {
auto lines = tokenizeString<Strings>(readFile(script), "\n"); auto lines = tokenizeString<Strings>(readFile(script), "\n");
if (std::regex_search(lines.front(), std::regex("^#!"))) { if (std::regex_search(lines.front(), std::regex("^#!"))) {
lines.pop_front(); lines.pop_front();
@ -126,7 +126,7 @@ void mainWrapped(int argc, char * * argv)
args.push_back(word); args.push_back(word);
} }
} }
} } catch (SysError &) { }
} }
parseCmdLine(myName, args, [&](Strings::iterator & arg, const Strings::iterator & end) { parseCmdLine(myName, args, [&](Strings::iterator & arg, const Strings::iterator & end) {