mirror of
https://github.com/NixOS/nix
synced 2025-07-03 10:21:47 +02:00
inline the usage of nix::readDirectory
`nix::readDirectory` is removed. `std::filesystem::directory_iterator` is used directly in places that used this util.
This commit is contained in:
parent
87ab3c0ea4
commit
1db7d1b840
18 changed files with 26 additions and 44 deletions
|
@ -17,10 +17,10 @@ struct State
|
|||
/* For each activated package, create symlinks */
|
||||
static void createLinks(State & state, const Path & srcDir, const Path & dstDir, int priority)
|
||||
{
|
||||
std::vector<std::filesystem::directory_entry> srcFiles;
|
||||
std::filesystem::directory_iterator srcFiles;
|
||||
|
||||
try {
|
||||
srcFiles = readDirectory(srcDir);
|
||||
srcFiles = std::filesystem::directory_iterator{srcDir};
|
||||
} catch (std::filesystem::filesystem_error & e) {
|
||||
if (e.code() == std::errc::not_a_directory) {
|
||||
warn("not including '%s' in the user environment because it's not a directory", srcDir);
|
||||
|
|
|
@ -161,7 +161,7 @@ void LocalStore::findTempRoots(Roots & tempRoots, bool censor)
|
|||
{
|
||||
/* Read the `temproots' directory for per-process temporary root
|
||||
files. */
|
||||
for (auto & i : readDirectory(tempRootsDir)) {
|
||||
for (auto & i : std::filesystem::directory_iterator{tempRootsDir}) {
|
||||
auto name = i.path().filename().string();
|
||||
if (name[0] == '.') {
|
||||
// Ignore hidden files. Some package managers (notably portage) create
|
||||
|
@ -228,7 +228,7 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R
|
|||
type = getFileType(path);
|
||||
|
||||
if (type == std::filesystem::file_type::directory) {
|
||||
for (auto & i : readDirectory(path))
|
||||
for (auto & i : std::filesystem::directory_iterator{path})
|
||||
findRoots(i.path().string(), i.symlink_status().type(), roots);
|
||||
}
|
||||
|
||||
|
|
|
@ -345,7 +345,7 @@ void initPlugins()
|
|||
for (const auto & pluginFile : settings.pluginFiles.get()) {
|
||||
std::vector<std::filesystem::path> pluginFiles;
|
||||
try {
|
||||
auto ents = readDirectory(pluginFile);
|
||||
auto ents = std::filesystem::directory_iterator{pluginFile};
|
||||
for (const auto & ent : ents)
|
||||
pluginFiles.emplace_back(ent.path());
|
||||
} catch (std::filesystem::filesystem_error & e) {
|
||||
|
|
|
@ -83,7 +83,7 @@ protected:
|
|||
{
|
||||
StorePathSet paths;
|
||||
|
||||
for (auto & entry : readDirectory(binaryCacheDir)) {
|
||||
for (auto & entry : std::filesystem::directory_iterator{binaryCacheDir}) {
|
||||
auto name = entry.path().filename().string();
|
||||
if (name.size() != 40 ||
|
||||
!hasSuffix(name, ".narinfo"))
|
||||
|
|
|
@ -1406,7 +1406,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
|
|||
|
||||
printInfo("checking link hashes...");
|
||||
|
||||
for (auto & link : readDirectory(linksDir)) {
|
||||
for (auto & link : std::filesystem::directory_iterator{linksDir}) {
|
||||
auto name = link.path().filename();
|
||||
printMsg(lvlTalkative, "checking contents of '%s'", name);
|
||||
PosixSourceAccessor accessor;
|
||||
|
@ -1498,7 +1498,7 @@ LocalStore::VerificationResult LocalStore::verifyAllValidPaths(RepairFlag repair
|
|||
database and the filesystem) in the loop below, in order to catch
|
||||
invalid states.
|
||||
*/
|
||||
for (auto & i : readDirectory(realStoreDir)) {
|
||||
for (auto & i : std::filesystem::directory_iterator{realStoreDir.to_string()}) {
|
||||
try {
|
||||
storePathsInStoreDir.insert({i.path().filename().string()});
|
||||
} catch (BadStorePath &) { }
|
||||
|
|
|
@ -144,8 +144,7 @@ static void canonicalisePathMetaData_(
|
|||
#endif
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
std::vector<std::filesystem::directory_entry> entries = readDirectory(path);
|
||||
for (auto & i : entries)
|
||||
for (auto & i : std::filesystem::directory_iterator{path})
|
||||
canonicalisePathMetaData_(
|
||||
i.path().string(),
|
||||
#ifndef _WIN32
|
||||
|
|
|
@ -37,7 +37,7 @@ std::pair<Generations, std::optional<GenerationNumber>> findGenerations(Path pro
|
|||
std::filesystem::path profileDir = dirOf(profile);
|
||||
auto profileName = std::string(baseNameOf(profile));
|
||||
|
||||
for (auto & i : readDirectory(profileDir.string())) {
|
||||
for (auto & i : std::filesystem::directory_iterator{profileDir}) {
|
||||
if (auto n = parseName(profileName, i.path().filename().string())) {
|
||||
auto path = i.path().string();
|
||||
gens.push_back({
|
||||
|
|
|
@ -21,10 +21,12 @@ void builtinUnpackChannel(
|
|||
|
||||
unpackTarfile(src, out);
|
||||
|
||||
auto entries = readDirectory(out);
|
||||
if (entries.size() != 1)
|
||||
auto entries = std::filesystem::directory_iterator{out};
|
||||
auto file_count = std::distance(entries, std::filesystem::directory_iterator{});
|
||||
|
||||
if (file_count != 1)
|
||||
throw Error("channel tarball '%s' contains more than one file", src);
|
||||
renameFile(entries[0].path().string(), (out + "/" + channelName));
|
||||
renameFile(entries->path().string(), (out + "/" + channelName));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue