mirror of
https://github.com/NixOS/nix.git
synced 2025-11-22 18:29:36 +01:00
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.
This commit is contained in:
parent
5caebab63a
commit
437b9b9879
4 changed files with 10 additions and 10 deletions
|
|
@ -99,7 +99,7 @@ TEST(references, scanForReferencesDeep)
|
||||||
// Create an in-memory file system with various reference patterns
|
// Create an in-memory file system with various reference patterns
|
||||||
auto accessor = make_ref<MemorySourceAccessor>();
|
auto accessor = make_ref<MemorySourceAccessor>();
|
||||||
accessor->root = File::Directory{
|
accessor->root = File::Directory{
|
||||||
.contents{
|
.entries{
|
||||||
{
|
{
|
||||||
// file1.txt: contains hash1
|
// file1.txt: contains hash1
|
||||||
"file1.txt",
|
"file1.txt",
|
||||||
|
|
@ -125,7 +125,7 @@ TEST(references, scanForReferencesDeep)
|
||||||
// subdir: a subdirectory
|
// subdir: a subdirectory
|
||||||
"subdir",
|
"subdir",
|
||||||
File::Directory{
|
File::Directory{
|
||||||
.contents{
|
.entries{
|
||||||
{
|
{
|
||||||
// subdir/file4.txt: contains hash1 again
|
// subdir/file4.txt: contains hash1 again
|
||||||
"file4.txt",
|
"file4.txt",
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ TEST_F(GitTest, both_roundrip)
|
||||||
|
|
||||||
auto files = make_ref<MemorySourceAccessor>();
|
auto files = make_ref<MemorySourceAccessor>();
|
||||||
files->root = File::Directory{
|
files->root = File::Directory{
|
||||||
.contents{
|
.entries{
|
||||||
{
|
{
|
||||||
"foo",
|
"foo",
|
||||||
File::Regular{
|
File::Regular{
|
||||||
|
|
@ -240,7 +240,7 @@ TEST_F(GitTest, both_roundrip)
|
||||||
{
|
{
|
||||||
"bar",
|
"bar",
|
||||||
File::Directory{
|
File::Directory{
|
||||||
.contents =
|
.entries =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"baz",
|
"baz",
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ struct MemorySourceAccessor : virtual SourceAccessor
|
||||||
{
|
{
|
||||||
using Name = std::string;
|
using Name = std::string;
|
||||||
|
|
||||||
std::map<Name, File, std::less<>> contents;
|
std::map<Name, File, std::less<>> entries;
|
||||||
|
|
||||||
bool operator==(const Directory &) const noexcept;
|
bool operator==(const Directory &) const noexcept;
|
||||||
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
|
// 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
|
inline bool
|
||||||
MemorySourceAccessor::File::Directory::operator<(const MemorySourceAccessor::File::Directory & other) const noexcept
|
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;
|
inline bool MemorySourceAccessor::File::operator==(const MemorySourceAccessor::File &) const noexcept = default;
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,13 @@ MemorySourceAccessor::File * MemorySourceAccessor::open(const CanonPath & path,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto & curDir = *curDirP;
|
auto & curDir = *curDirP;
|
||||||
|
|
||||||
auto i = curDir.contents.find(name);
|
auto i = curDir.entries.find(name);
|
||||||
if (i == curDir.contents.end()) {
|
if (i == curDir.entries.end()) {
|
||||||
if (!create)
|
if (!create)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
else {
|
else {
|
||||||
newF = true;
|
newF = true;
|
||||||
i = curDir.contents.insert(
|
i = curDir.entries.insert(
|
||||||
i,
|
i,
|
||||||
{
|
{
|
||||||
std::string{name},
|
std::string{name},
|
||||||
|
|
@ -106,7 +106,7 @@ MemorySourceAccessor::DirEntries MemorySourceAccessor::readDirectory(const Canon
|
||||||
throw Error("file '%s' does not exist", path);
|
throw Error("file '%s' does not exist", path);
|
||||||
if (auto * d = std::get_if<File::Directory>(&f->raw)) {
|
if (auto * d = std::get_if<File::Directory>(&f->raw)) {
|
||||||
DirEntries res;
|
DirEntries res;
|
||||||
for (auto & [name, file] : d->contents)
|
for (auto & [name, file] : d->entries)
|
||||||
res.insert_or_assign(name, file.lstat().type);
|
res.insert_or_assign(name, file.lstat().type);
|
||||||
return res;
|
return res;
|
||||||
} else
|
} else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue