1 #include "ostree_repo.h"
3 #include "logging/logging.h"
6 OSTreeObject::ptr OSTreeRepo::GetObject(
const uint8_t sha256[32],
const OstreeObjectType type)
const {
11 otable::const_iterator obj_it = ObjectTable.find(hash);
12 if (obj_it != ObjectTable.cend()) {
13 return obj_it->second;
16 const std::map<OstreeObjectType, std::string> exts{{OstreeObjectType::OSTREE_OBJECT_TYPE_FILE,
".filez"},
17 {OstreeObjectType::OSTREE_OBJECT_TYPE_DIR_TREE,
".dirtree"},
18 {OstreeObjectType::OSTREE_OBJECT_TYPE_DIR_META,
".dirmeta"},
19 {OstreeObjectType::OSTREE_OBJECT_TYPE_COMMIT,
".commit"}};
20 const std::string objpath = hash.string().insert(2, 1,
'/');
21 OSTreeObject::ptr object;
23 for (
int i = 0; i < 3; ++i) {
25 LOG_WARNING <<
"OSTree hash " << hash <<
" not found. Retrying (attempt " << i <<
" of 3)";
27 if (type != OstreeObjectType::OSTREE_OBJECT_TYPE_UNKNOWN) {
28 if (CheckForObject(hash, objpath + exts.at(type),
object)) {
32 for (
auto it = exts.cbegin(); it != exts.cend(); ++it) {
33 if (CheckForObject(hash, objpath + it->second,
object)) {
42 bool OSTreeRepo::CheckForObject(
const OSTreeHash &hash,
const std::string &path, OSTreeObject::ptr &
object)
const {
43 if (FetchObject(std::string(
"objects/") + path)) {
44 object = OSTreeObject::ptr(
new OSTreeObject(*
this, path));
45 ObjectTable[hash] = object;
46 LOG_DEBUG <<
"Fetched OSTree object " << path;