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:
parent
b4950404ba
commit
c371070580
14 changed files with 61 additions and 99 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue