mirror of
https://github.com/NixOS/nix
synced 2025-07-02 05:11:47 +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
|
@ -31,14 +31,14 @@ void removeOldGenerations(std::string dir)
|
|||
checkInterrupt();
|
||||
|
||||
auto path = dir + "/" + i.name;
|
||||
auto type = i.type == DT_UNKNOWN ? getFileType(path) : i.type;
|
||||
auto type = i.type == std::filesystem::file_type::unknown ? getFileType(path) : i.type;
|
||||
|
||||
if (type == DT_LNK && canWrite) {
|
||||
if (type == std::filesystem::file_type::symlink && canWrite) {
|
||||
std::string link;
|
||||
try {
|
||||
link = readLink(path);
|
||||
} catch (SysError & e) {
|
||||
if (e.errNo == ENOENT) continue;
|
||||
} catch (std::filesystem::filesystem_error & e) {
|
||||
if (e.code() == std::errc::no_such_file_or_directory) continue;
|
||||
throw;
|
||||
}
|
||||
if (link.find("link") != std::string::npos) {
|
||||
|
@ -49,7 +49,7 @@ void removeOldGenerations(std::string dir)
|
|||
} else
|
||||
deleteOldGenerations(path, dryRun);
|
||||
}
|
||||
} else if (type == DT_DIR) {
|
||||
} else if (type == std::filesystem::file_type::directory) {
|
||||
removeOldGenerations(path);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue