1 #include "unencrypted_properties.h"
7 const char* key = "key";
8 const char* ref = "ref";
9 const char* props = "props";
10 const char* is_default = "is_default";
15 const char* unencrypted_folder = "unencrypted";
18 std::string UnencryptedProperties::GetPath(const char* device)
20 return std::string() + device + "/" + unencrypted_folder;
23 UnencryptedProperties::UnencryptedProperties(const char* device)
24 : folder_(GetPath(device))
26 DIR* dir = opendir(folder_.c_str());
34 UnencryptedProperties::UnencryptedProperties()
38 template<> std::string UnencryptedProperties::Get(const char* name,
39 std::string default_value) const
41 if (!OK()) return default_value;
42 std::ifstream i(folder_ + "/" + name, std::ios::binary);
47 i.seekg(0, std::ios::end);
48 int length = i.tellg();
49 i.seekg(0, std::ios::beg);
54 std::string s(length, 0);
55 i.read(&s[0], length);
63 template<> bool UnencryptedProperties::Set(const char* name, std::string const& value)
65 if (!OK()) return false;
66 std::ofstream o(folder_ + "/" + name, std::ios::binary);
71 UnencryptedProperties UnencryptedProperties::GetChild(const char* name) const
73 UnencryptedProperties up;
76 std::string directory(folder_ + "/" + name);
77 if (mkdir(directory.c_str(), 700) == -1 && errno != EEXIST) {
81 up.folder_ = directory;
85 bool UnencryptedProperties::Remove(const char* name)
87 if (!OK()) return false;
88 if (remove((folder_ + "/" + name).c_str())
96 bool UnencryptedProperties::OK() const
98 return !folder_.empty();