1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 20:01:15 +02:00

Use std::filesystem functions in more places

This makes for shorter and more portable code.

The only tricky part is catching exceptions: I just searched for near by
`catch (Error &)` or `catch (SysError &)` and adjusted them to `catch
(std::filesystem::filesystem_error &)` according to my human judgement.

Good for windows portability; will help @siddhantk232 with his GSOC
project.
This commit is contained in:
John Ericson 2024-05-07 00:14:49 -04:00
parent b4950404ba
commit c371070580
14 changed files with 61 additions and 99 deletions

View file

@ -134,13 +134,17 @@ SourceAccessor::DirEntries PosixSourceAccessor::readDirectory(const CanonPath &
DirEntries res;
for (auto & entry : nix::readDirectory(makeAbsPath(path).string())) {
std::optional<Type> type;
// cannot exhaustively enumerate because implementation-specific
// additional file types are allowed.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-enum"
switch (entry.type) {
case DT_REG: type = Type::tRegular; break;
#ifndef _WIN32
case DT_LNK: type = Type::tSymlink; break;
#endif
case DT_DIR: type = Type::tDirectory; break;
case std::filesystem::file_type::regular: type = Type::tRegular; break;
case std::filesystem::file_type::symlink: type = Type::tSymlink; break;
case std::filesystem::file_type::directory: type = Type::tDirectory; break;
default: type = tMisc;
}
#pragma GCC diagnostic pop
res.emplace(entry.name, type);
}
return res;