summaryrefslogtreecommitdiff
path: root/netfs/lib
diff options
context:
space:
mode:
Diffstat (limited to 'netfs/lib')
-rw-r--r--netfs/lib/defaultMapper.cpp2
-rw-r--r--netfs/lib/entCache.h16
-rw-r--r--netfs/lib/entCache.impl.h11
3 files changed, 21 insertions, 8 deletions
diff --git a/netfs/lib/defaultMapper.cpp b/netfs/lib/defaultMapper.cpp
index 27b20d3..865cca1 100644
--- a/netfs/lib/defaultMapper.cpp
+++ b/netfs/lib/defaultMapper.cpp
@@ -4,7 +4,7 @@
namespace NetFS::Mapping {
DefaultMapper::DefaultMapper() :
- DefaultMapper(std::make_shared<EntCache<User>>(), std::make_shared<EntCache<Group>>())
+ users(std::make_shared<UserEntCache>()), groups(std::make_shared<GroupEntCache>(users))
{
}
diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h
index 7a9a3ef..e394b05 100644
--- a/netfs/lib/entCache.h
+++ b/netfs/lib/entCache.h
@@ -1,6 +1,7 @@
#ifndef ENTCACHE_H
#define ENTCACHE_H
+#include "entries.h"
#include "entryResolver.h"
#include <c++11Helpers.h>
#include <shared_mutex>
@@ -26,7 +27,7 @@ public:
};
protected:
- void fillCache() const noexcept;
+ virtual void fillCache() const noexcept = 0;
template<class key_t>[[nodiscard]] entry_ptr getEntryInternal(const key_t &) const noexcept;
template<class key_t>[[nodiscard]] entry_ptr getEntryNoFill(const key_t &) const noexcept;
@@ -36,4 +37,17 @@ protected:
mutable time_t fillTime {0};
};
+class UserEntCache : public EntCache<User> {
+ void fillCache() const noexcept override;
+};
+
+class GroupEntCache : public EntCache<Group> {
+public:
+ GroupEntCache(EntryResolverPtr<User>);
+
+private:
+ void fillCache() const noexcept override;
+ EntryResolverPtr<User> users;
+};
+
#endif
diff --git a/netfs/lib/entCache.impl.h b/netfs/lib/entCache.impl.h
index 6523d32..1d7bbc7 100644
--- a/netfs/lib/entCache.impl.h
+++ b/netfs/lib/entCache.impl.h
@@ -53,9 +53,8 @@ EntCache<entry_t>::getEntryNoFill(const key_t & key) const noexcept
const int BUFLEN = 8196;
-template<>
void
-EntCache<User>::fillCache() const noexcept
+UserEntCache::fillCache() const noexcept
{
Lock(lock);
setpwent();
@@ -70,9 +69,10 @@ EntCache<User>::fillCache() const noexcept
time(&fillTime);
}
-template<>
+GroupEntCache::GroupEntCache(EntryResolverPtr<User> u) : users(std::move(u)) { }
+
void
-EntCache<Group>::fillCache() const noexcept
+GroupEntCache::fillCache() const noexcept
{
Lock(lock);
setgrent();
@@ -80,11 +80,10 @@ EntCache<Group>::fillCache() const noexcept
idcache->clear();
struct group grpbuf {
}, *grp;
- EntCache<User> instance;
while (getgrent_r(&grpbuf, buf.data(), buf.size(), &grp) == 0) {
auto g = std::make_shared<Group>(grp->gr_gid, grp->gr_name);
for (auto member = grp->gr_mem; *member; member++) {
- if (auto ent = instance.getEntry(*member)) {
+ if (auto ent = users->getEntry(*member)) {
g->members.insert(ent->id);
}
}