Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
ostree_dir_repo.cc
1 #include "ostree_dir_repo.h"
2 
3 #include <string>
4 
5 #include <boost/property_tree/ini_parser.hpp>
6 
7 #include "logging/logging.h"
8 
9 namespace fs = boost::filesystem;
10 namespace pt = boost::property_tree;
11 
12 bool OSTreeDirRepo::LooksValid() const {
13  fs::path objects_dir(root_ / "/objects");
14  fs::path refs_dir(root_ / "/refs");
15  fs::path config_file(root_ / "/config");
16  if (fs::is_directory(objects_dir) && fs::is_directory(refs_dir) && fs::is_regular(config_file)) {
17  pt::ptree config;
18  try {
19  pt::read_ini(config_file.string(), config);
20  if (config.get<std::string>("core.mode") != "archive-z2") {
21  LOG_WARNING << "OSTree repo is not in archive-z2 format";
22  return false;
23  }
24  return true;
25 
26  } catch (const pt::ini_parser_error &error) {
27  LOG_WARNING << "Couldn't parse OSTree config file: " << config_file;
28  return false;
29  } catch (const pt::ptree_error &error) {
30  LOG_WARNING << "Could not find core.mode in OSTree config file";
31  return false;
32  }
33  } else {
34  return false;
35  }
36 }
37 
38 OSTreeRef OSTreeDirRepo::GetRef(const std::string &refname) const { return OSTreeRef(*this, refname); }
39 
40 bool OSTreeDirRepo::FetchObject(const boost::filesystem::path &path) const {
41  return fs::is_regular_file((root_ / path).string());
42 }
43 
44 // vim: set tabstop=2 shiftwidth=2 expandtab:
OSTreeRef
Definition: ostree_ref.h:13