blob: e2e8bfd22247e0b8437f63944f7ca054e8995ce1 [file] [log] [blame]
Michael Tritz60bc20f2017-07-29 23:32:21 -05001#include "config.h"
2#include <experimental/filesystem>
3#include <cereal/archives/binary.hpp>
4#include <fstream>
5#include "serialize.hpp"
6
7namespace openpower
8{
9namespace software
10{
11namespace updater
12{
13
14namespace fs = std::experimental::filesystem;
15
16void 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
29void 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
40void 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