From 9ee590e11301cda2b5d6341fb77f13369c3107e6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 4 Mar 2024 21:54:35 +0100 Subject: [PATCH 1/2] PosixSourceAccessor::cachedLstat(): Use absolute path Using the relative path can cause collisions between cache entries for PosixSourceAccessors with different roots. --- src/libutil/posix-source-accessor.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libutil/posix-source-accessor.cc b/src/libutil/posix-source-accessor.cc index f8ec7fc6b..e91943c4c 100644 --- a/src/libutil/posix-source-accessor.cc +++ b/src/libutil/posix-source-accessor.cc @@ -85,16 +85,18 @@ bool PosixSourceAccessor::pathExists(const CanonPath & path) std::optional PosixSourceAccessor::cachedLstat(const CanonPath & path) { - static Sync>> _cache; + static Sync>> _cache; + + auto absPath = makeAbsPath(path); { auto cache(_cache.lock()); - auto i = cache->find(path); + auto i = cache->find(absPath); if (i != cache->end()) return i->second; } std::optional st{std::in_place}; - if (::lstat(makeAbsPath(path).c_str(), &*st)) { + if (::lstat(absPath.c_str(), &*st)) { if (errno == ENOENT || errno == ENOTDIR) st.reset(); else @@ -103,7 +105,7 @@ std::optional PosixSourceAccessor::cachedLstat(const CanonPath & pa auto cache(_cache.lock()); if (cache->size() >= 16384) cache->clear(); - cache->emplace(path, st); + cache->emplace(absPath, st); return st; } From 4967c5ff6ba96b27ad1d855b3b32712c0fc3dfcf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 4 Mar 2024 22:24:12 +0100 Subject: [PATCH 2/2] Fix macOS build --- src/libutil/posix-source-accessor.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libutil/posix-source-accessor.cc b/src/libutil/posix-source-accessor.cc index e91943c4c..41c2db59a 100644 --- a/src/libutil/posix-source-accessor.cc +++ b/src/libutil/posix-source-accessor.cc @@ -85,9 +85,11 @@ bool PosixSourceAccessor::pathExists(const CanonPath & path) std::optional PosixSourceAccessor::cachedLstat(const CanonPath & path) { - static Sync>> _cache; + static Sync>> _cache; - auto absPath = makeAbsPath(path); + // Note: we convert std::filesystem::path to Path because the + // former is not hashable on libc++. + Path absPath = makeAbsPath(path); { auto cache(_cache.lock());