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();
131 auto path_to_id = getFullPath(
id);
132 auto correct_container_path = path_to_id / key;
135 ARMARX_DEBUG <<
"Contains container?: " << contains_container;
137 return contains_container;
149 return fileExists(
id, key);
155 std::vector<unsigned char>&
data)
163 ensureFullPathExists(
id,
true);
164 ensureFileExists(
id, key,
true);
166 if (enoughDiskSpaceLeft())
168 writeDataToFile(
id, key,
data);
172 ARMARX_DEBUG <<
"Not enough DiskSpace available for DiskPersistance-Strategy";
176 std::vector<unsigned char>
182 return std::vector<unsigned char>();
185 if (fileExists(
id, key))
187 return readDataFromFile(
id, key);
190 return std::vector<unsigned char>();
193 std::filesystem::path
194 DiskPersistence::getMemoryParentPath()
196 std::string p = memoryParentPath_.string();
203 std::filesystem::path
222 auto p = getFullPath(
id);
229 auto p = getFullPath(
id) /
filename;
235 bool createIfNotExistent)
237 auto p = getFullPath(
id);
244 bool createIfNotExistent)
246 auto p = getFullPath(
id) /
filename;
253 const std::vector<unsigned char>&
data)
255 auto p = getFullPath(
id) /
filename;
259 std::vector<unsigned char>
263 auto p = getFullPath(
id) /
filename;
267 std::vector<std::filesystem::path>
270 if (fullPathExists(
id))
272 auto p = getFullPath(
id);
276 return std::vector<std::filesystem::path>();
279 std::vector<std::filesystem::path>
282 if (fullPathExists(
id))
284 auto p = getFullPath(
id);
288 return std::vector<std::filesystem::path>();
292 DiskPersistence::enoughDiskSpaceLeft()
294 std::string path_to_disk = this->getMemoryParentPath();
295 ARMARX_DEBUG <<
"Checking availability of disk space at " << path_to_disk;
297 if (std::filesystem::exists(path_to_disk))
302 int const conversion_factor = 1024;
304 auto available_space = space_info.available /
305 (conversion_factor * conversion_factor * conversion_factor);
307 << space_info.capacity /
308 (conversion_factor * conversion_factor * conversion_factor)
312 (conversion_factor * conversion_factor * conversion_factor)
315 << space_info.available /
316 (conversion_factor * conversion_factor * conversion_factor)
321 return static_cast<bool>(available_space >= this->
minDiskSpace);
323 catch (
const std::filesystem::filesystem_error& e)
330 ARMARX_DEBUG <<
"Error while trying to get info on available disk space";
336 ARMARX_DEBUG <<
"Cannot find path to disk and thus cannot check if enough space is "