Skip to content
Snippets Groups Projects
Commit 1897cfe7 authored by Joana Plewnia's avatar Joana Plewnia
Browse files

Merge branch 'fix/mem_export_check_space' into 'master'

Fix/mem export check space

See merge request !519
parents e24094ff 5083b1f4
No related branches found
No related tags found
1 merge request!519Fix/mem export check space
Pipeline #22507 failed
......@@ -133,7 +133,9 @@ namespace armarx::armem::server::ltm::detail::mixin
DiskMemoryItemMixin::ensureFullPathExists(bool createIfNotExistent) const
{
auto p = getFullPath();
util::fs::ensureDirectoryExists(p, createIfNotExistent);
if(enoughDiskSpaceLeft()){
util::fs::ensureDirectoryExists(p, createIfNotExistent);
}
}
void
......@@ -141,15 +143,72 @@ namespace armarx::armem::server::ltm::detail::mixin
bool createIfNotExistent) const
{
auto p = getFullPath() / filename;
util::fs::ensureFileExists(p, createIfNotExistent);
if(enoughDiskSpaceLeft()){
util::fs::ensureDirectoryExists(p, createIfNotExistent);
}
}
bool
DiskMemoryItemMixin::enoughDiskSpaceLeft() const
{
std::string path_to_disk = this->getMemoryBasePath();;
ARMARX_DEBUG << "Checking availability of disk space at " << path_to_disk;
if (std::filesystem::exists(path_to_disk))
{
try
{
auto space_info = std::filesystem::space(path_to_disk);
int const conversion_factor = 1024;
auto available_space = space_info.available /
(conversion_factor * conversion_factor * conversion_factor);
ARMARX_DEBUG << "Capacity: "
<< space_info.capacity /
(conversion_factor * conversion_factor * conversion_factor)
<< " GB\n";
ARMARX_DEBUG << "Free space: "
<< space_info.free /
(conversion_factor * conversion_factor * conversion_factor)
<< " GB\n";
ARMARX_DEBUG << "Available space: "
<< space_info.available /
(conversion_factor * conversion_factor * conversion_factor)
<< " GB\n";
return static_cast<bool>(available_space >= 50);
}
catch (const std::filesystem::filesystem_error& e)
{
ARMARX_WARNING << "Error: " << e.what() << '\n';
return false;
}
catch (...){
ARMARX_DEBUG << "Error while trying to get info on available disk space";
return false;
}
}
else
{
ARMARX_DEBUG << "Cannot find path to disk and thus cannot check if enough space is "
"still available";
return true;
}
}
void
DiskMemoryItemMixin::writeDataToFile(const std::string& filename,
const std::vector<unsigned char>& data) const
{
auto p = getFullPath() / filename;
util::fs::writeDataToFile(p, data);
if (enoughDiskSpaceLeft())
{
auto p = getFullPath() / filename;
util::fs::writeDataToFile(p, data);
}
else
{
ARMARX_DEBUG << "Canot store snapshot as not enough disk space is available";
}
}
std::vector<unsigned char>
......
......@@ -32,6 +32,7 @@ namespace armarx::armem::server::ltm::detail::mixin
bool memoryBasePathExists() const;
bool fullPathExists() const;
bool fileExists(const std::string& filename) const;
bool enoughDiskSpaceLeft() const;
void ensureMemoryBasePathExists(bool createIfNotExistent = false) const;
void ensureFullPathExists(bool createIfNotExistent = false) const;
......@@ -72,6 +73,7 @@ namespace armarx::armem::server::ltm::detail::mixin
private:
std::filesystem::path memoryBasePath;
std::string memoryBasePathString;
std::string pathToHome;
std::string exportName;
armem::MemoryID _id;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment