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 const 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  OSTreeObject::ptr GetObject(const uint8_t sha256[32], OstreeObjectType type) const;
31 
32  protected:
33  virtual bool FetchObject(const boost::filesystem::path& path) const = 0;
34 
35  bool CheckForObject(const OSTreeHash& hash, const std::string& path, OSTreeObject::ptr& object) const;
36 
37  typedef std::map<OSTreeHash, OSTreeObject::ptr> otable;
38  mutable otable ObjectTable; // Makes sure that the same commit object is not added twice
39 };
40 
41 /**
42  * Thrown by GetObject when the object requested is not present in the
43  * repository.
44  */
45 class OSTreeObjectMissing : std::exception {
46  public:
47  explicit OSTreeObjectMissing(const OSTreeHash _missing_object) : missing_object_(_missing_object) {}
48 
49  const char* what() const noexcept override { return "OSTree repository is missing an object"; }
50 
51  OSTreeHash missing_object() const { return missing_object_; }
52 
53  private:
54  OSTreeHash missing_object_;
55 };
56 // vim: set tabstop=2 shiftwidth=2 expandtab:
57 #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:45
OSTreeHash
Definition: ostree_hash.h:9
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