Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
ostree_repo.cc
1 #include "ostree_repo.h"
2 
3 #include "logging/logging.h"
4 
5 OSTreeObject::ptr OSTreeRepo::GetObject(const uint8_t sha256[32], const OstreeObjectType type) const {
6  return GetObject(OSTreeHash(sha256), type);
7 }
8 
9 OSTreeObject::ptr OSTreeRepo::GetObject(const OSTreeHash hash, const OstreeObjectType type) const {
10  otable::const_iterator obj_it = ObjectTable.find(hash);
11  if (obj_it != ObjectTable.cend()) {
12  return obj_it->second;
13  }
14 
15  const std::map<OstreeObjectType, std::string> exts{{OstreeObjectType::OSTREE_OBJECT_TYPE_FILE, ".filez"},
16  {OstreeObjectType::OSTREE_OBJECT_TYPE_DIR_TREE, ".dirtree"},
17  {OstreeObjectType::OSTREE_OBJECT_TYPE_DIR_META, ".dirmeta"},
18  {OstreeObjectType::OSTREE_OBJECT_TYPE_COMMIT, ".commit"}};
19  const std::string objpath = hash.string().insert(2, 1, '/');
20  OSTreeObject::ptr object;
21 
22  for (int i = 0; i < 3; ++i) {
23  if (i > 0) {
24  LOG_WARNING << "OSTree hash " << hash << " not found. Retrying (attempt " << i << " of 3)";
25  }
26  if (type != OstreeObjectType::OSTREE_OBJECT_TYPE_UNKNOWN) {
27  if (CheckForObject(hash, objpath + exts.at(type), object)) {
28  return object;
29  }
30  } else {
31  for (auto it = exts.cbegin(); it != exts.cend(); ++it) {
32  if (CheckForObject(hash, objpath + it->second, object)) {
33  return object;
34  }
35  }
36  }
37  }
38  throw OSTreeObjectMissing(hash);
39 }
40 
41 bool OSTreeRepo::CheckForObject(const OSTreeHash &hash, const std::string &path, OSTreeObject::ptr &object) const {
42  if (FetchObject(std::string("objects/") + path)) {
43  object = OSTreeObject::ptr(new OSTreeObject(*this, path));
44  ObjectTable[hash] = object;
45  LOG_DEBUG << "Fetched OSTree object " << path;
46  return true;
47  }
48  return false;
49 }
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
OSTreeObject
Definition: ostree_object.h:30
OstreeObjectType
OstreeObjectType
Types of OSTree objects, borrowed from libostree/ostree-core.h.
Definition: garage_common.h:34