From 437b9b9879558ce36788efb9db26f0baec87b570 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 19 Nov 2025 17:25:07 -0500 Subject: [PATCH] Rename `MemorySourceAccessor::File::Directory::{contents -> entries}` This matches the "NAR Listing" JSON format, and also helps distinguish from regular file contents. Why we want to match that will become clear in the next comments, when we will in fact use (variations of) this data type for NAR listings. --- src/libstore-tests/references.cc | 4 ++-- src/libutil-tests/git.cc | 4 ++-- src/libutil/include/nix/util/memory-source-accessor.hh | 4 ++-- src/libutil/memory-source-accessor.cc | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libstore-tests/references.cc b/src/libstore-tests/references.cc index 9cecd573e..f2c6fb51e 100644 --- a/src/libstore-tests/references.cc +++ b/src/libstore-tests/references.cc @@ -99,7 +99,7 @@ TEST(references, scanForReferencesDeep) // Create an in-memory file system with various reference patterns auto accessor = make_ref(); accessor->root = File::Directory{ - .contents{ + .entries{ { // file1.txt: contains hash1 "file1.txt", @@ -125,7 +125,7 @@ TEST(references, scanForReferencesDeep) // subdir: a subdirectory "subdir", File::Directory{ - .contents{ + .entries{ { // subdir/file4.txt: contains hash1 again "file4.txt", diff --git a/src/libutil-tests/git.cc b/src/libutil-tests/git.cc index 6180a4cfc..9d749b492 100644 --- a/src/libutil-tests/git.cc +++ b/src/libutil-tests/git.cc @@ -230,7 +230,7 @@ TEST_F(GitTest, both_roundrip) auto files = make_ref(); files->root = File::Directory{ - .contents{ + .entries{ { "foo", File::Regular{ @@ -240,7 +240,7 @@ TEST_F(GitTest, both_roundrip) { "bar", File::Directory{ - .contents = + .entries = { { "baz", diff --git a/src/libutil/include/nix/util/memory-source-accessor.hh b/src/libutil/include/nix/util/memory-source-accessor.hh index eba282fe1..6aadc53a3 100644 --- a/src/libutil/include/nix/util/memory-source-accessor.hh +++ b/src/libutil/include/nix/util/memory-source-accessor.hh @@ -35,7 +35,7 @@ struct MemorySourceAccessor : virtual SourceAccessor { using Name = std::string; - std::map> contents; + std::map> entries; bool operator==(const Directory &) const noexcept; // TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet. @@ -95,7 +95,7 @@ inline bool MemorySourceAccessor::File::Directory::operator==( inline bool MemorySourceAccessor::File::Directory::operator<(const MemorySourceAccessor::File::Directory & other) const noexcept { - return contents < other.contents; + return entries < other.entries; } inline bool MemorySourceAccessor::File::operator==(const MemorySourceAccessor::File &) const noexcept = default; diff --git a/src/libutil/memory-source-accessor.cc b/src/libutil/memory-source-accessor.cc index a9ffb7746..6cc51a7fa 100644 --- a/src/libutil/memory-source-accessor.cc +++ b/src/libutil/memory-source-accessor.cc @@ -29,13 +29,13 @@ MemorySourceAccessor::File * MemorySourceAccessor::open(const CanonPath & path, return nullptr; auto & curDir = *curDirP; - auto i = curDir.contents.find(name); - if (i == curDir.contents.end()) { + auto i = curDir.entries.find(name); + if (i == curDir.entries.end()) { if (!create) return nullptr; else { newF = true; - i = curDir.contents.insert( + i = curDir.entries.insert( i, { std::string{name}, @@ -106,7 +106,7 @@ MemorySourceAccessor::DirEntries MemorySourceAccessor::readDirectory(const Canon throw Error("file '%s' does not exist", path); if (auto * d = std::get_if(&f->raw)) { DirEntries res; - for (auto & [name, file] : d->contents) + for (auto & [name, file] : d->entries) res.insert_or_assign(name, file.lstat().type); return res; } else