1 #include "ostree_repo.h"
3 #include "logging/logging.h"
5 OSTreeObject::ptr OSTreeRepo::GetObject(
const uint8_t sha256[32],
const OstreeObjectType type)
const {
10 otable::const_iterator obj_it = ObjectTable.find(hash);
11 if (obj_it != ObjectTable.cend()) {
12 return obj_it->second;
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;
22 for (
int i = 0; i < 3; ++i) {
24 LOG_WARNING <<
"OSTree hash " << hash <<
" not found. Retrying (attempt " << i <<
" of 3)";
26 if (type != OstreeObjectType::OSTREE_OBJECT_TYPE_UNKNOWN) {
27 if (CheckForObject(hash, objpath + exts.at(type), object)) {
31 for (
auto it = exts.cbegin(); it != exts.cend(); ++it) {
32 if (CheckForObject(hash, objpath + it->second,
object)) {
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;