diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-04-06 19:55:06 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-04-06 19:55:06 +0100 |
commit | 2cfbb3eef0fc55932a2e3e0113bd3089f8688adb (patch) | |
tree | 1fdb2b8ef8fbdb2aea95d8ebe2e876f938847608 | |
parent | Support a fallback value in EntCache (diff) | |
download | netfs-2cfbb3eef0fc55932a2e3e0113bd3089f8688adb.tar.bz2 netfs-2cfbb3eef0fc55932a2e3e0113bd3089f8688adb.tar.xz netfs-2cfbb3eef0fc55932a2e3e0113bd3089f8688adb.zip |
EntryResolvers return where they got the resolution fromnetfs-1.4.0
-rw-r--r-- | netfs/ice/entryResolver.h | 11 | ||||
-rw-r--r-- | netfs/lib/entCache.h | 11 | ||||
-rw-r--r-- | netfs/lib/entCache.impl.h | 17 | ||||
-rw-r--r-- | netfs/unittests/testLib.cpp | 20 |
4 files changed, 44 insertions, 15 deletions
diff --git a/netfs/ice/entryResolver.h b/netfs/ice/entryResolver.h index cbdc789..14f2d5d 100644 --- a/netfs/ice/entryResolver.h +++ b/netfs/ice/entryResolver.h @@ -1,13 +1,20 @@ #ifndef NETFS_ENTRYRESOLVER_H #define NETFS_ENTRYRESOLVER_H +#include <cstddef> + +enum class ResolvedAs : uint8_t { + Real, + Fallback, +}; + template <typename id_t, typename name_t> class EntryResolver { public: virtual ~EntryResolver() = default; - virtual void getID(const name_t &, id_t *) const = 0; - virtual void getName(const id_t &, name_t *) const = 0; + virtual ResolvedAs getID(const name_t &, id_t *) const = 0; + virtual ResolvedAs getName(const id_t &, name_t *) const = 0; }; #endif diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h index e6a77dc..e0a06b5 100644 --- a/netfs/lib/entCache.h +++ b/netfs/lib/entCache.h @@ -39,10 +39,15 @@ class EntCache : public EntryResolver<decltype(entry_t::id), decltype(entry_t::n using name_t = decltype(entry_t::name); using entry_ptr = std::shared_ptr<entry_t>; - void getID(const name_t &, id_t *) const override; - void getName(const id_t &, name_t *) const override; + struct Resolution : public entry_ptr { + Resolution(entry_ptr, ResolvedAs = ResolvedAs::Real); + ResolvedAs resolution; + }; + + ResolvedAs getID(const name_t &, id_t *) const override; + ResolvedAs getName(const id_t &, name_t *) const override; template<class key_t> - entry_ptr getEntry(const key_t &) const; + Resolution getEntry(const key_t &) const; void setFallback(entry_t fb); void clearFallback(); diff --git a/netfs/lib/entCache.impl.h b/netfs/lib/entCache.impl.h index e83fb49..e0a8f85 100644 --- a/netfs/lib/entCache.impl.h +++ b/netfs/lib/entCache.impl.h @@ -38,24 +38,33 @@ template<class entry_t> EntCache<entry_t>::~EntCache() = default; template<class entry_t> -void +ResolvedAs EntCache<entry_t>::getID(const EntCache<entry_t>::name_t & u, EntCache<entry_t>::id_t * target) const { auto e = getEntry(u); *target = e->id; + return e.resolution; } template<class entry_t> -void +ResolvedAs EntCache<entry_t>::getName(const EntCache<entry_t>::id_t & u, EntCache<entry_t>::name_t * target) const { auto e = getEntry(u); *target = e->name; + return e.resolution; +} + +template<class entry_t> +EntCache<entry_t>::Resolution::Resolution(entry_ptr e, ResolvedAs res) : + entry_ptr(std::move(e)), + resolution(res) +{ } template<class entry_t> template<class key_t> -typename EntCache<entry_t>::entry_ptr +typename EntCache<entry_t>::Resolution EntCache<entry_t>::getEntry(const key_t & key) const { if (fillTime + 60 > time(nullptr)) { @@ -68,7 +77,7 @@ EntCache<entry_t>::getEntry(const key_t & key) const return ent; } if (fallback) { - return fallback; + return { fallback, ResolvedAs::Fallback }; } throw NetFS::SystemError(EPERM); } diff --git a/netfs/unittests/testLib.cpp b/netfs/unittests/testLib.cpp index 91ca683..1e80590 100644 --- a/netfs/unittests/testLib.cpp +++ b/netfs/unittests/testLib.cpp @@ -4,6 +4,14 @@ #include <entCache.impl.h> #include <lockHelpers.h> +namespace std { + ostream & operator<<(ostream & strm, const ResolvedAs & r) + { + strm << r; + return strm; + } +} + struct TestEntry { TestEntry(int i, std::string n) : id(i), @@ -48,14 +56,14 @@ BOOST_DATA_TEST_CASE(notfoundname, BadNames, name) BOOST_DATA_TEST_CASE(foundid, GoodNames ^ GoodIds, name, id) { std::string outname; - BOOST_REQUIRE_NO_THROW(getName(id, &outname)); + BOOST_CHECK_EQUAL(getName(id, &outname), ResolvedAs::Real); BOOST_CHECK_EQUAL(name, outname); } BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id) { int outid; - BOOST_REQUIRE_NO_THROW(getID(name, &outid)); + BOOST_CHECK_EQUAL(getID(name, &outid), ResolvedAs::Real); BOOST_CHECK_EQUAL(id, outid); } @@ -71,28 +79,28 @@ BOOST_FIXTURE_TEST_SUITE(tecfb, TestEntCacheWithFallback); BOOST_DATA_TEST_CASE(notfoundid, BadIds, id) { std::string outname; - BOOST_REQUIRE_NO_THROW(getName(id, &outname)); + BOOST_CHECK_EQUAL(getName(id, &outname), ResolvedAs::Fallback); BOOST_CHECK_EQUAL(outname, fallback->name); } BOOST_DATA_TEST_CASE(notfoundname, BadNames, name) { int outid; - BOOST_REQUIRE_NO_THROW(getID(name, &outid)); + BOOST_CHECK_EQUAL(getID(name, &outid), ResolvedAs::Fallback); BOOST_CHECK_EQUAL(outid, fallback->id); } BOOST_DATA_TEST_CASE(foundid, GoodNames ^ GoodIds, name, id) { std::string outname; - BOOST_REQUIRE_NO_THROW(getName(id, &outname)); + BOOST_CHECK_EQUAL(getName(id, &outname), ResolvedAs::Real); BOOST_CHECK_EQUAL(name, outname); } BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id) { int outid; - BOOST_REQUIRE_NO_THROW(getID(name, &outid)); + BOOST_CHECK_EQUAL(getID(name, &outid), ResolvedAs::Real); BOOST_CHECK_EQUAL(id, outid); } |