Aktualizr
C++ SOTA Client
packagemanagerconfig.h
1 #ifndef PACKAGE_MANAGER_PACKAGEMANAGERCONFIG_H_
2 #define PACKAGE_MANAGER_PACKAGEMANAGERCONFIG_H_
3 
4 #include <boost/filesystem.hpp>
5 #include <boost/property_tree/ptree_fwd.hpp>
6 #include <string>
7 
8 #include "utilities/config_utils.h"
9 
10 enum class PackageManager { kNone = 0, kOstree, kDebian };
11 
12 struct PackageConfig {
13  PackageManager type{PackageManager::kOstree};
14  std::string os;
15  boost::filesystem::path sysroot;
16  std::string ostree_server;
17  boost::filesystem::path packages_file{"/usr/package.manifest"};
18 
19  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
20  void writeToStream(std::ostream& out_stream) const;
21 };
22 
23 template <>
24 inline void CopyFromConfig(PackageManager& dest, const std::string& option_name,
25  const boost::property_tree::ptree& pt) {
26  boost::optional<std::string> value = pt.get_optional<std::string>(option_name);
27  if (value.is_initialized()) {
28  std::string pm_type{StripQuotesFromStrings(value.get())};
29  if (pm_type == "ostree") {
30  dest = PackageManager::kOstree;
31  } else if (pm_type == "debian") {
32  dest = PackageManager::kDebian;
33  } else {
34  dest = PackageManager::kNone;
35  }
36  }
37 }
38 
39 #endif // PACKAGE_MANAGER_PACKAGEMANAGERCONFIG_H_