diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2020-06-07 22:23:40 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2020-07-20 21:39:02 +0200 |
commit | 8ac21c24e49bc3702c55d1c796f969f1d1f6128b (patch) | |
tree | 6a24dcad00857212bd5584807ddd794de65ee01f /src/storage.h | |
parent | 692e64613c45d6cfb9444931084b4a04965e826e (diff) |
Storage: typed heads
Diffstat (limited to 'src/storage.h')
-rw-r--r-- | src/storage.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/storage.h b/src/storage.h index 1635d40..18ac1ad 100644 --- a/src/storage.h +++ b/src/storage.h @@ -13,6 +13,7 @@ using std::shared_ptr; using std::unique_ptr; using std::unordered_map; using std::unordered_set; +using std::tuple; using std::variant; using std::vector; @@ -29,6 +30,11 @@ public: virtual optional<vector<uint8_t>> loadBytes(const Digest &) const = 0; virtual void storeBytes(const Digest &, const vector<uint8_t> &) = 0; + virtual optional<Digest> headRef(UUID type, UUID id) const = 0; + virtual vector<tuple<UUID, Digest>> headRefs(UUID type) const = 0; + virtual UUID storeHead(UUID type, const Digest & dgst) = 0; + virtual bool replaceHead(UUID type, UUID id, const Digest & old, const Digest & dgst) = 0; + virtual optional<vector<uint8_t>> loadKey(const Digest &) const = 0; virtual void storeKey(const Digest &, const vector<uint8_t> &) = 0; }; @@ -44,6 +50,11 @@ public: virtual optional<vector<uint8_t>> loadBytes(const Digest &) const override; virtual void storeBytes(const Digest &, const vector<uint8_t> &) override; + virtual optional<Digest> headRef(UUID type, UUID id) const override; + virtual vector<tuple<UUID, Digest>> headRefs(UUID type) const override; + virtual UUID storeHead(UUID type, const Digest & dgst) override; + virtual bool replaceHead(UUID type, UUID id, const Digest & old, const Digest & dgst) override; + virtual optional<vector<uint8_t>> loadKey(const Digest &) const override; virtual void storeKey(const Digest &, const vector<uint8_t> &) override; @@ -51,8 +62,11 @@ private: static constexpr size_t CHUNK = 16384; fs::path objectPath(const Digest &) const; + fs::path headPath(UUID id, UUID type) const; fs::path keyPath(const Digest &) const; + FILE * openLockFile(const fs::path & path) const; + fs::path root; }; @@ -67,11 +81,17 @@ public: virtual optional<vector<uint8_t>> loadBytes(const Digest &) const override; virtual void storeBytes(const Digest &, const vector<uint8_t> &) override; + virtual optional<Digest> headRef(UUID type, UUID id) const override; + virtual vector<tuple<UUID, Digest>> headRefs(UUID type) const override; + virtual UUID storeHead(UUID type, const Digest & dgst) override; + virtual bool replaceHead(UUID type, UUID id, const Digest & old, const Digest & dgst) override; + virtual optional<vector<uint8_t>> loadKey(const Digest &) const override; virtual void storeKey(const Digest &, const vector<uint8_t> &) override; private: unordered_map<Digest, vector<uint8_t>> storage; + unordered_map<UUID, vector<tuple<UUID, Digest>>> heads; unordered_map<Digest, vector<uint8_t>> keys; }; @@ -89,6 +109,11 @@ public: virtual optional<vector<uint8_t>> loadBytes(const Digest &) const override; virtual void storeBytes(const Digest &, const vector<uint8_t> &) override; + virtual optional<Digest> headRef(UUID type, UUID id) const override; + virtual vector<tuple<UUID, Digest>> headRefs(UUID type) const override; + virtual UUID storeHead(UUID type, const Digest & dgst) override; + virtual bool replaceHead(UUID type, UUID id, const Digest & old, const Digest & dgst) override; + virtual optional<vector<uint8_t>> loadKey(const Digest &) const override; virtual void storeKey(const Digest &, const vector<uint8_t> &) override; |