8 std::vector<std::string>
11 ARMARX_DEBUG <<
"DiskPersistence: GetContainerKey, memID=" <<
id.str();
13 std::vector<std::string> containers;
22 if (!
id.hasEntityName() ||
id.hasTimestamp())
24 std::vector<std::filesystem::path> dirs = getAllDirectories(
id);
27 for (
auto& path : dirs)
29 std::string container = path.filename().string();
31 if (!container.empty())
33 containers.emplace_back(container);
40 std::vector<std::filesystem::path> dayDirs = getAllDirectories(
id);
42 for (std::filesystem::path& dayDir : dayDirs)
46 ARMARX_WARNING <<
"Found a non-date folder inside an entity '" <<
id.str()
47 <<
"' with name '" << dayDir.filename() <<
"'. "
48 <<
"Ignoring this folder, however this is a bad situation.";
54 for (std::filesystem::path& secondDir : secondDirs)
58 ARMARX_WARNING <<
"Found a non-timestamp folder inside an entity '"
59 <<
id.str() <<
"' hours folder with name '"
60 << secondDir.filename() <<
"'. "
61 <<
"Ignoring this folder, however this is a bad situation.";
65 std::vector<std::filesystem::path> timestampDirs =
68 for (std::filesystem::path& timestampDir : timestampDirs)
73 <<
"Found a non-timestamp folder inside an entity '" <<
id.str()
74 <<
"' seconds folder with name '" << timestampDir.filename()
76 <<
"Ignoring this folder, however this is a bad situation.";
80 std::string container = timestampDir.filename().string();
82 if (!container.empty())
84 containers.emplace_back(container);
94 std::vector<std::string>
100 return std::vector<std::string>();
103 std::vector<std::filesystem::path>
files = getAllFiles(
id);
104 std::vector<std::string> filesStr;
106 for (
auto& path :
files)
108 std::string item = path.filename().string();
112 filesStr.emplace_back(item);
122 ARMARX_DEBUG <<
"Contains container key=" << key <<
"? mem id=" <<
id.str();
132 ARMARX_DEBUG <<
"Compare stored key=" << storedKey <<
", key=" << key;
133 if (storedKey == key)
153 return fileExists(
id, key);
159 std::vector<unsigned char>&
data)
167 ensureFullPathExists(
id,
true);
168 ensureFileExists(
id, key,
true);
170 if (enoughDiskSpaceLeft())
172 writeDataToFile(
id, key,
data);
176 ARMARX_DEBUG <<
"Not enough DiskSpace available for DiskPersistance-Strategy";
180 std::vector<unsigned char>
186 return std::vector<unsigned char>();
189 if (fileExists(
id, key))
191 return readDataFromFile(
id, key);
194 return std::vector<unsigned char>();
197 std::filesystem::path
198 DiskPersistence::getMemoryParentPath()
200 std::string p = memoryParentPath_.string();
207 std::filesystem::path
226 auto p = getFullPath(
id);
233 auto p = getFullPath(
id) /
filename;
239 bool createIfNotExistent)
241 auto p = getFullPath(
id);
248 bool createIfNotExistent)
250 auto p = getFullPath(
id) /
filename;
257 const std::vector<unsigned char>&
data)
259 auto p = getFullPath(
id) /
filename;
263 std::vector<unsigned char>
267 auto p = getFullPath(
id) /
filename;
271 std::vector<std::filesystem::path>
274 if (fullPathExists(
id))
276 auto p = getFullPath(
id);
280 return std::vector<std::filesystem::path>();
283 std::vector<std::filesystem::path>
286 if (fullPathExists(
id))
288 auto p = getFullPath(
id);
292 return std::vector<std::filesystem::path>();
296 DiskPersistence::enoughDiskSpaceLeft()
298 std::string path_to_disk = this->getMemoryParentPath();
299 ARMARX_DEBUG <<
"Checking availability of disk space at " << path_to_disk;
301 if (std::filesystem::exists(path_to_disk))
306 int const conversion_factor = 1024;
308 auto available_space = space_info.available /
309 (conversion_factor * conversion_factor * conversion_factor);
311 << space_info.capacity /
312 (conversion_factor * conversion_factor * conversion_factor)
316 (conversion_factor * conversion_factor * conversion_factor)
319 << space_info.available /
320 (conversion_factor * conversion_factor * conversion_factor)
325 return static_cast<bool>(available_space >= this->
minDiskSpace);
327 catch (
const std::filesystem::filesystem_error& e)
334 ARMARX_DEBUG <<
"Error while trying to get info on available disk space";
340 ARMARX_DEBUG <<
"Cannot find path to disk and thus cannot check if enough space is "