1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 23:03:53 -04:00

<nix/buildenv.nix>: Skip non-directory top-level paths

Fixes https://github.com/NixOS/nix/issues/1934 (at least the "error:
opening directory '/nix/store/...-linux-config-4.4.14': Not a
directory" issue).
This commit is contained in:
Eelco Dolstra 2018-04-05 19:32:13 +02:00
parent 3fbaa230a2
commit 5c904e10eb
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -26,12 +26,23 @@ static unsigned long symlinks;
/* For each activated package, create symlinks */ /* For each activated package, create symlinks */
static void createLinks(const Path & srcDir, const Path & dstDir, int priority) static void createLinks(const Path & srcDir, const Path & dstDir, int priority)
{ {
auto srcFiles = readDirectory(srcDir); DirEntries srcFiles;
try {
srcFiles = readDirectory(srcDir);
} catch (SysError & e) {
if (e.errNo == ENOTDIR) {
printError("warning: not including '%s' in the user environment because it's not a directory", srcDir);
return;
}
throw;
}
for (const auto & ent : srcFiles) { for (const auto & ent : srcFiles) {
if (ent.name[0] == '.') if (ent.name[0] == '.')
/* not matched by glob */ /* not matched by glob */
continue; continue;
const auto & srcFile = srcDir + "/" + ent.name; auto srcFile = srcDir + "/" + ent.name;
auto dstFile = dstDir + "/" + ent.name; auto dstFile = dstDir + "/" + ent.name;
/* The files below are special-cased to that they don't show up /* The files below are special-cased to that they don't show up
@ -44,9 +55,10 @@ static void createLinks(const Path & srcDir, const Path & dstDir, int priority)
hasSuffix(srcFile, "/nix-support") || hasSuffix(srcFile, "/nix-support") ||
hasSuffix(srcFile, "/perllocal.pod") || hasSuffix(srcFile, "/perllocal.pod") ||
hasSuffix(srcFile, "/info/dir") || hasSuffix(srcFile, "/info/dir") ||
hasSuffix(srcFile, "/log")) { hasSuffix(srcFile, "/log"))
continue; continue;
} else if (isDirectory(srcFile)) {
else if (isDirectory(srcFile)) {
struct stat dstSt; struct stat dstSt;
auto res = lstat(dstFile.c_str(), &dstSt); auto res = lstat(dstFile.c_str(), &dstSt);
if (res == 0) { if (res == 0) {
@ -68,7 +80,9 @@ static void createLinks(const Path & srcDir, const Path & dstDir, int priority)
} }
} else if (errno != ENOENT) } else if (errno != ENOENT)
throw SysError(format("getting status of '%1%'") % dstFile); throw SysError(format("getting status of '%1%'") % dstFile);
} else { }
else {
struct stat dstSt; struct stat dstSt;
auto res = lstat(dstFile.c_str(), &dstSt); auto res = lstat(dstFile.c_str(), &dstSt);
if (res == 0) { if (res == 0) {
@ -90,6 +104,7 @@ static void createLinks(const Path & srcDir, const Path & dstDir, int priority)
} else if (errno != ENOENT) } else if (errno != ENOENT)
throw SysError(format("getting status of '%1%'") % dstFile); throw SysError(format("getting status of '%1%'") % dstFile);
} }
createSymlink(srcFile, dstFile); createSymlink(srcFile, dstFile);
priorities[dstFile] = priority; priorities[dstFile] = priority;
symlinks++; symlinks++;
@ -105,24 +120,18 @@ static Path out;
static void addPkg(const Path & pkgDir, int priority) static void addPkg(const Path & pkgDir, int priority)
{ {
if (done.find(pkgDir) != done.end()) if (done.count(pkgDir)) return;
return;
done.insert(pkgDir); done.insert(pkgDir);
createLinks(pkgDir, out, priority); createLinks(pkgDir, out, priority);
auto propagatedFN = pkgDir + "/nix-support/propagated-user-env-packages";
std::string propagated; try {
{ for (const auto & p : tokenizeString<std::vector<string>>(
AutoCloseFD fd = open(propagatedFN.c_str(), O_RDONLY | O_CLOEXEC); readFile(pkgDir + "/nix-support/propagated-user-env-packages"), " \n"))
if (!fd) { if (!done.count(p))
if (errno == ENOENT)
return;
throw SysError(format("opening '%1%'") % propagatedFN);
}
propagated = readFile(fd.get());
}
for (const auto & p : tokenizeString<std::vector<string>>(propagated, " \n"))
if (done.find(p) == done.end())
postponed.insert(p); postponed.insert(p);
} catch (SysError & e) {
if (e.errNo != ENOENT && e.errNo != ENOTDIR) throw;
}
} }
struct Package { struct Package {
@ -190,4 +199,3 @@ void builtinBuildenv(const BasicDerivation & drv)
} }
} }