Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
ostree_repo.h
1 #ifndef SOTA_CLIENT_TOOLS_OSTREE_REPO_H_
2 #define SOTA_CLIENT_TOOLS_OSTREE_REPO_H_
3 
4 #include <map>
5 #include <string>
6 
7 #include <boost/filesystem.hpp>
8 
9 #include "garage_common.h"
10 #include "ostree_hash.h"
11 #include "ostree_object.h"
12 
13 class OSTreeRef;
14 
15 /**
16  * A source repository to read OSTree objects from. This can be either a directory
17  * on disk, or a URL in the garage-deploy case.
18  */
19 class OSTreeRepo {
20  public:
21  using ptr = std::shared_ptr<OSTreeRepo>;
22  OSTreeRepo& operator=(const OSTreeRepo&) = delete;
23 
24  virtual ~OSTreeRepo() = default;
25  virtual bool LooksValid() const = 0;
26  virtual boost::filesystem::path root() const = 0;
27  virtual OSTreeRef GetRef(const std::string& refname) const = 0;
28 
29  OSTreeObject::ptr GetObject(OSTreeHash hash, OstreeObjectType type) const;
30  // NOLINTNEXTLINE(modernize-avoid-c-arrays)
31  OSTreeObject::ptr GetObject(const uint8_t sha256[32], OstreeObjectType type) const;
32 
33  protected:
34  virtual bool FetchObject(const boost::filesystem::path& path) const = 0;
35 
36  bool CheckForObject(const OSTreeHash& hash, const std::string& path, OSTreeObject::ptr& object) const;
37 
38  typedef std::map<OSTreeHash, OSTreeObject::ptr> otable;
39  mutable otable ObjectTable; // Makes sure that the same commit object is not added twice
40 };
41 
42 /**
43  * Thrown by GetObject when the object requested is not present in the
44  * repository.
45  */
46 class OSTreeObjectMissing : std::exception {
47  public:
48  explicit OSTreeObjectMissing(const OSTreeHash _missing_object) : missing_object_(_missing_object) {}
49 
50  const char* what() const noexcept override { return "OSTree repository is missing an object"; }
51 
52  OSTreeHash missing_object() const { return missing_object_; }
53 
54  private:
55  OSTreeHash missing_object_;
56 };
57 // vim: set tabstop=2 shiftwidth=2 expandtab:
58 #endif // SOTA_CLIENT_TOOLS_OSTREE_REPO_H_
OSTreeObjectMissing
Thrown by GetObject when the object requested is not present in the repository.
Definition: ostree_repo.h:46
OSTreeHash
Definition: ostree_hash.h:10
OSTreeRepo
A source repository to read OSTree objects from.
Definition: ostree_repo.h:19
garage_common.h
OSTreeRef
Definition: ostree_ref.h:13
OstreeObjectType
OstreeObjectType
Types of OSTree objects, borrowed from libostree/ostree-core.h.
Definition: garage_common.h:34