mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
Try to fix macOS Nixpkgs lib test failure
Sometimes we read a directory with children we cannot stat. It's a pitty we even try to stat at all (wasteful) in the `DT_UNKNOWN` case, but at least this should get rid of the failure.
This commit is contained in:
parent
a3c573950b
commit
72a0d4b022
2 changed files with 30 additions and 9 deletions
|
@ -256,6 +256,14 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catch (std::filesystem::filesystem_error & e) {
|
||||||
|
/* We only ignore permanent failures. */
|
||||||
|
if (e.code() == std::errc::permission_denied || e.code() == std::errc::no_such_file_or_directory || e.code() == std::errc::not_a_directory)
|
||||||
|
printInfo("cannot read potential root '%1%'", path);
|
||||||
|
else
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
catch (SysError & e) {
|
catch (SysError & e) {
|
||||||
/* We only ignore permanent failures. */
|
/* We only ignore permanent failures. */
|
||||||
if (e.errNo == EACCES || e.errNo == ENOENT || e.errNo == ENOTDIR)
|
if (e.errNo == EACCES || e.errNo == ENOENT || e.errNo == ENOTDIR)
|
||||||
|
|
|
@ -133,18 +133,31 @@ SourceAccessor::DirEntries PosixSourceAccessor::readDirectory(const CanonPath &
|
||||||
assertNoSymlinks(path);
|
assertNoSymlinks(path);
|
||||||
DirEntries res;
|
DirEntries res;
|
||||||
for (auto & entry : nix::readDirectory(makeAbsPath(path).string())) {
|
for (auto & entry : nix::readDirectory(makeAbsPath(path).string())) {
|
||||||
std::optional<Type> type;
|
auto type = [&]() -> std::optional<Type> {
|
||||||
|
std::filesystem::file_type nativeType;
|
||||||
|
try {
|
||||||
|
nativeType = entry.symlink_status().type();
|
||||||
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
|
// We cannot always stat the child. (Ideally there is no
|
||||||
|
// stat because the native directory entry has the type
|
||||||
|
// already, but this isn't always the case.)
|
||||||
|
if (e.code() == std::errc::permission_denied || e.code() == std::errc::operation_not_permitted)
|
||||||
|
return std::nullopt;
|
||||||
|
else throw;
|
||||||
|
}
|
||||||
|
|
||||||
// cannot exhaustively enumerate because implementation-specific
|
// cannot exhaustively enumerate because implementation-specific
|
||||||
// additional file types are allowed.
|
// additional file types are allowed.
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wswitch-enum"
|
#pragma GCC diagnostic ignored "-Wswitch-enum"
|
||||||
switch (entry.symlink_status().type()) {
|
switch (nativeType) {
|
||||||
case std::filesystem::file_type::regular: type = Type::tRegular; break;
|
case std::filesystem::file_type::regular: return Type::tRegular; break;
|
||||||
case std::filesystem::file_type::symlink: type = Type::tSymlink; break;
|
case std::filesystem::file_type::symlink: return Type::tSymlink; break;
|
||||||
case std::filesystem::file_type::directory: type = Type::tDirectory; break;
|
case std::filesystem::file_type::directory: return Type::tDirectory; break;
|
||||||
default: type = tMisc;
|
default: return tMisc;
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
}();
|
||||||
res.emplace(entry.path().filename().string(), type);
|
res.emplace(entry.path().filename().string(), type);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in a new issue