blob: 064a4c60852d01e77142b27c300d0508145b527f [file] [log] [blame]
Krzysztof Grobelny73da6902020-09-24 13:42:04 +02001#pragma once
2
3#include "interfaces/json_storage.hpp"
4
5class PersistentJsonStorage : public interfaces::JsonStorage
6{
7 public:
8 explicit PersistentJsonStorage(const DirectoryPath& directory);
9
10 void store(const FilePath& subPath, const nlohmann::json& data) override;
11 bool remove(const FilePath& subPath) override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010012 bool exist(const FilePath& path) const override;
Krzysztof Grobelny73da6902020-09-24 13:42:04 +020013 std::optional<nlohmann::json> load(const FilePath& subPath) const override;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010014 std::vector<FilePath> list() const override;
Krzysztof Grobelny73da6902020-09-24 13:42:04 +020015
16 private:
17 DirectoryPath directory;
18
19 static std::filesystem::path join(const std::filesystem::path&,
20 const std::filesystem::path&);
21 static void limitPermissions(const std::filesystem::path& path);
Krzysztof Grobelnya06626d2022-11-24 15:22:40 +000022 static void assertThatPathIsNotSymlink(const std::filesystem::path& path);
Krzysztof Grobelny73da6902020-09-24 13:42:04 +020023};