1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-14 14:32:42 +01: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

@ -24,7 +24,7 @@ void builtinUnpackChannel(
auto entries = readDirectory(out);
if (entries.size() != 1)
throw Error("channel tarball '%s' contains more than one file", src);
renameFile((out + "/" + entries[0].name), (out + "/" + channelName));
renameFile(entries[0].path().string(), (out + "/" + channelName));
}
}

View file

@ -160,14 +160,15 @@ void LocalStore::findTempRoots(Roots & tempRoots, bool censor)
/* Read the `temproots' directory for per-process temporary root
files. */
for (auto & i : readDirectory(tempRootsDir)) {
if (i.name[0] == '.') {
auto name = i.path().filename().string();
if (name[0] == '.') {
// Ignore hidden files. Some package managers (notably portage) create
// those to keep the directory alive.
continue;
}
Path path = tempRootsDir + "/" + i.name;
Path path = i.path();
pid_t pid = std::stoi(i.name);
pid_t pid = std::stoi(name);
debug("reading temporary root file '%1%'", path);
AutoCloseFD fd(open(path.c_str(), O_CLOEXEC | O_RDWR, 0666));
@ -222,7 +223,7 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R
if (type == std::filesystem::file_type::directory) {
for (auto & i : readDirectory(path))
findRoots(path + "/" + i.name, i.type, roots);
findRoots(i.path().string(), i.symlink_status().type(), roots);
}
else if (type == std::filesystem::file_type::symlink) {

View file

@ -1388,15 +1388,16 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
printInfo("checking link hashes...");
for (auto & link : readDirectory(linksDir)) {
printMsg(lvlTalkative, "checking contents of '%s'", link.name);
Path linkPath = linksDir + "/" + link.name;
auto name = link.path().filename();
printMsg(lvlTalkative, "checking contents of '%s'", name);
Path linkPath = linksDir / name;
PosixSourceAccessor accessor;
std::string hash = hashPath(
{getFSSourceAccessor(), CanonPath(linkPath)},
FileIngestionMethod::Recursive, HashAlgorithm::SHA256).to_string(HashFormat::Nix32, false);
if (hash != link.name) {
if (hash != name.string()) {
printError("link '%s' was modified! expected hash '%s', got '%s'",
linkPath, link.name, hash);
linkPath, name, hash);
if (repair) {
if (unlink(linkPath.c_str()) == 0)
printInfo("removed link '%s'", linkPath);
@ -1483,7 +1484,7 @@ LocalStore::VerificationResult LocalStore::verifyAllValidPaths(RepairFlag repair
*/
for (auto & i : readDirectory(realStoreDir)) {
try {
storePathsInStoreDir.insert({i.name});
storePathsInStoreDir.insert({i.path().filename().string()});
} catch (BadStorePath &) { }
}

View file

@ -136,9 +136,9 @@ static void canonicalisePathMetaData_(
}
if (S_ISDIR(st.st_mode)) {
DirEntries entries = readDirectory(path);
std::vector<std::filesystem::directory_entry> entries = readDirectory(path);
for (auto & i : entries)
canonicalisePathMetaData_(path + "/" + i.name, uidRange, inodesSeen);
canonicalisePathMetaData_(i.path().string(), uidRange, inodesSeen);
}
}