1 #include "ostree_http_repo.h"
7 #include <boost/property_tree/ini_parser.hpp>
9 namespace pt = boost::property_tree;
11 bool OSTreeHttpRepo::LooksValid()
const {
12 if (FetchObject(
"config")) {
15 pt::read_ini((root_ /
"config").
string(), config);
16 if (config.get<std::string>(
"core.mode") !=
"archive-z2") {
17 LOG_WARNING <<
"OSTree repo is not in archive-z2 format";
22 }
catch (
const pt::ini_parser_error &error) {
23 LOG_WARNING <<
"Couldn't parse OSTree config file: " << (root_ /
"config").
string();
25 }
catch (
const pt::ptree_error &error) {
26 LOG_WARNING <<
"Could not find core.mode in OSTree config file";
34 OSTreeRef OSTreeHttpRepo::GetRef(
const std::string &refname)
const {
return OSTreeRef(*server_, refname); }
36 bool OSTreeHttpRepo::FetchObject(
const boost::filesystem::path &path)
const {
37 CURLcode err = CURLE_OK;
38 server_->InjectIntoCurl(path.string(), easy_handle_.get());
39 boost::filesystem::create_directories((root_ / path).parent_path());
40 std::string filename = (root_ / path).
string();
41 int fp = open(filename.c_str(), O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
43 LOG_ERROR <<
"Failed to open file: " << filename;
46 curlEasySetoptWrapper(easy_handle_.get(), CURLOPT_WRITEDATA, &fp);
47 err = curl_easy_perform(easy_handle_.get());
50 if (err == CURLE_HTTP_RETURNED_ERROR) {
53 remove((root_ / path).c_str());
55 }
else if (err != CURLE_OK) {
57 char *last_url =
nullptr;
58 curl_easy_getinfo(easy_handle_.get(), CURLINFO_EFFECTIVE_URL, &last_url);
59 LOG_ERROR <<
"Failed to get object:" << curl_easy_strerror(err);
60 if (last_url !=
nullptr) {
61 LOG_ERROR <<
"Url: " << last_url;
63 remove((root_ / path).c_str());
70 size_t OSTreeHttpRepo::curl_handle_write(
void *buffer,
size_t size,
size_t nmemb,
void *userp) {
71 return static_cast<size_t>(write(*
static_cast<int *
>(userp), buffer, nmemb * size));