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)
139 ARMARX_DEBUG <<
"Nope, does not contain the container!";
153 return fileExists(
id, key);
159 std::vector<unsigned char>&
data)
167 ensureFullPathExists(
id,
true);
168 ensureFileExists(
id, key,
true);
169 if (enoughDiskSpaceLeft())
171 writeDataToFile(
id, key,
data);
175 ARMARX_DEBUG <<
"Not enough DiskSpace available for DiskPersistance-Strategy";
179 std::vector<unsigned char>
185 return std::vector<unsigned char>();
188 if (fileExists(
id, key))
190 return readDataFromFile(
id, key);
193 return std::vector<unsigned char>();
196 std::filesystem::path
197 DiskPersistence::getMemoryParentPath()
199 std::string p = memoryParentPath_.string();
206 std::filesystem::path
225 auto p = getFullPath(
id);
232 auto p = getFullPath(
id) /
filename;
238 bool createIfNotExistent)
240 auto p = getFullPath(
id);
247 bool createIfNotExistent)
249 auto p = getFullPath(
id) /
filename;
256 const std::vector<unsigned char>&
data)
258 auto p = getFullPath(
id) /
filename;
262 std::vector<unsigned char>
266 auto p = getFullPath(
id) /
filename;
270 std::vector<std::filesystem::path>
273 if (fullPathExists(
id))
275 auto p = getFullPath(
id);
279 return std::vector<std::filesystem::path>();
282 std::vector<std::filesystem::path>
285 if (fullPathExists(
id))
287 auto p = getFullPath(
id);
291 return std::vector<std::filesystem::path>();
295 DiskPersistence::enoughDiskSpaceLeft()
297 std::string path_to_disk = this->getMemoryParentPath();
298 ARMARX_DEBUG <<
"Checking availability of disk space at " << path_to_disk;
300 if (std::filesystem::exists(path_to_disk))
305 int const conversion_factor = 1024;
307 auto available_space = space_info.available /
308 (conversion_factor * conversion_factor * conversion_factor);
310 << space_info.capacity /
311 (conversion_factor * conversion_factor * conversion_factor)
315 (conversion_factor * conversion_factor * conversion_factor)
318 << space_info.available /
319 (conversion_factor * conversion_factor * conversion_factor)
324 return static_cast<bool>(available_space >= this->
minDiskSpace);
326 catch (
const std::filesystem::filesystem_error& e)
333 ARMARX_DEBUG <<
"Error while trying to get info on available disk space";
339 ARMARX_DEBUG <<
"Cannot find path to disk and thus cannot check if enough space is "