1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-01 16:41:47 +02:00

Replace our DirEntry with std::filesystem's

This commit is contained in:
John Ericson 2024-05-07 11:29:33 -04:00
parent c371070580
commit a3c573950b
18 changed files with 52 additions and 59 deletions

View file

@ -47,26 +47,26 @@ std::map<std::string, std::string> getCgroups(const Path & cgroupFile)
return cgroups;
}
static CgroupStats destroyCgroup(const Path & cgroup, bool returnStats)
static CgroupStats destroyCgroup(const std::filesystem::path & cgroup, bool returnStats)
{
if (!pathExists(cgroup)) return {};
auto procsFile = cgroup + "/cgroup.procs";
auto procsFile = cgroup / "cgroup.procs";
if (!pathExists(procsFile))
throw Error("'%s' is not a cgroup", cgroup);
/* Use the fast way to kill every process in a cgroup, if
available. */
auto killFile = cgroup + "/cgroup.kill";
auto killFile = cgroup / "cgroup.kill";
if (pathExists(killFile))
writeFile(killFile, "1");
/* Otherwise, manually kill every process in the subcgroups and
this cgroup. */
for (auto & entry : readDirectory(cgroup)) {
if (entry.type != std::filesystem::file_type::directory) continue;
destroyCgroup(cgroup + "/" + entry.name, false);
if (entry.symlink_status().type() != std::filesystem::file_type::directory) continue;
destroyCgroup(cgroup / entry.path().filename(), false);
}
int round = 1;
@ -111,7 +111,7 @@ static CgroupStats destroyCgroup(const Path & cgroup, bool returnStats)
CgroupStats stats;
if (returnStats) {
auto cpustatPath = cgroup + "/cpu.stat";
auto cpustatPath = cgroup / "cpu.stat";
if (pathExists(cpustatPath)) {
for (auto & line : tokenizeString<std::vector<std::string>>(readFile(cpustatPath), "\n")) {