blob: 8c97c89ea4c5dc2b224bef2707de73c728040a6f [file] [log] [blame]
Saqib Khan5d532672017-08-09 10:44:50 -05001#include "config.h"
2#include <experimental/filesystem>
3#include <cereal/archives/json.hpp>
4#include <fstream>
5#include "serialize.hpp"
6
7namespace phosphor
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());
25 cereal::JSONOutputArchive oarchive(os);
26 oarchive(cereal::make_nvp("priority", 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);
35 cereal::JSONInputArchive iarchive(is);
36 iarchive(cereal::make_nvp("priority", 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 phosphor
50} // namespace software
51} // namespace openpower