Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | #include <experimental/filesystem> |
| 3 | #include <cereal/archives/binary.hpp> |
| 4 | #include <fstream> |
| 5 | #include "serialize.hpp" |
| 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace software |
| 10 | { |
| 11 | namespace updater |
| 12 | { |
| 13 | |
| 14 | namespace fs = std::experimental::filesystem; |
| 15 | |
| 16 | void storeToFile(std::string versionId, uint8_t priority) |
| 17 | { |
| 18 | if(!fs::is_directory(PERSIST_DIR)) |
| 19 | { |
| 20 | fs::create_directory(PERSIST_DIR); |
| 21 | } |
| 22 | std::string path = PERSIST_DIR + versionId; |
| 23 | |
| 24 | std::ofstream os(path.c_str(), std::ios::binary); |
| 25 | cereal::BinaryOutputArchive oarchive(os); |
| 26 | oarchive(priority); |
| 27 | } |
| 28 | |
| 29 | void restoreFromFile(std::string versionId, uint8_t *priority) |
| 30 | { |
| 31 | std::string path = PERSIST_DIR + versionId; |
| 32 | if (fs::exists(path)) |
| 33 | { |
| 34 | std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); |
| 35 | cereal::BinaryInputArchive iarchive(is); |
| 36 | iarchive(*priority); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | void removeFile(std::string versionId) |
| 41 | { |
| 42 | std::string path = PERSIST_DIR + versionId; |
| 43 | if (fs::exists(path)) |
| 44 | { |
| 45 | fs::remove(path); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | } // namespace updater |
| 50 | } // namespace software |
| 51 | } // namespace openpower |