Line data Source code
1 : /*! 2 : * \file esys/repo/manifest/loaderesysrepo_manifest.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2020-2021 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/manifest/loaderesysrepo.h" 20 : #include "esys/repo/manifest/file.h" 21 : 22 : #include <boost/filesystem.hpp> 23 : 24 : namespace esys::repo::manifest 25 : { 26 : 27 15 : LoaderESysRepo::LoaderESysRepo() 28 15 : : LoaderBase() 29 : { 30 15 : } 31 : 32 15 : LoaderESysRepo::~LoaderESysRepo() = default; 33 : 34 15 : Result LoaderESysRepo::run() 35 : { 36 30 : if (get_config_folder() == nullptr) return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR); 37 45 : if (get_config_folder()->get_config() == nullptr) return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR); 38 45 : if (get_config_folder()->get_config()->get_manifest_type() != manifest::Type::ESYSREPO_MANIFEST) 39 0 : return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR); 40 45 : if (get_config_folder()->get_config()->get_manifest_path().empty()) 41 0 : return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR); 42 : 43 15 : boost::filesystem::path path; 44 15 : manifest::File loader; 45 : 46 30 : path = get_config_folder()->get_path(); 47 30 : path /= get_config_folder()->get_config()->get_manifest_path(); 48 45 : path = boost::filesystem::absolute(path).make_preferred(); 49 : 50 30 : if (get_manifest() == nullptr) set_manifest(std::make_shared<Manifest>()); 51 : 52 15 : loader.set_data(get_manifest()); 53 : 54 30 : boost::filesystem::path rel_path = boost::filesystem::relative(path); 55 : 56 15 : Result result = loader.read(path.string()); 57 15 : if (result.error()) 58 0 : error("Couldn't load ESysRepo manifest : " + rel_path.string()); 59 : else 60 30 : debug(0, "Loaded ESysRepo manifest : " + rel_path.string()); 61 : 62 30 : return ESYSREPO_RESULT(result); 63 30 : } 64 : 65 : } // namespace esys::repo::manifest