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

added check for enough available disk space

only tested in simulation
parent e24094ff
No related branches found
No related tags found
1 merge request!519Fix/mem export check space
Pipeline #22500 failed
...@@ -144,12 +144,62 @@ namespace armarx::armem::server::ltm::detail::mixin ...@@ -144,12 +144,62 @@ namespace armarx::armem::server::ltm::detail::mixin
util::fs::ensureFileExists(p, createIfNotExistent); util::fs::ensureFileExists(p, createIfNotExistent);
} }
bool
DiskMemoryItemMixin::enoughDiskSpaceLeft() const
{
std::string path_to_disk = "/dev/mapper/ubuntu--vg-root\\";
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;
}
}
else
{
ARMARX_DEBUG << "Cannot find path to disk and thus cannot check if enough space is "
"still available";
return true;
}
}
void void
DiskMemoryItemMixin::writeDataToFile(const std::string& filename, DiskMemoryItemMixin::writeDataToFile(const std::string& filename,
const std::vector<unsigned char>& data) const const std::vector<unsigned char>& data) const
{ {
auto p = getFullPath() / filename; if (enoughDiskSpaceLeft())
util::fs::writeDataToFile(p, data); {
auto p = getFullPath() / filename;
util::fs::writeDataToFile(p, data);
}
else
{
ARMARX_DEBUG << "Canot store snapshot as not enough disk space available";
}
} }
std::vector<unsigned char> std::vector<unsigned char>
......
...@@ -32,6 +32,7 @@ namespace armarx::armem::server::ltm::detail::mixin ...@@ -32,6 +32,7 @@ namespace armarx::armem::server::ltm::detail::mixin
bool memoryBasePathExists() const; bool memoryBasePathExists() const;
bool fullPathExists() const; bool fullPathExists() const;
bool fileExists(const std::string& filename) const; bool fileExists(const std::string& filename) const;
bool enoughDiskSpaceLeft() const;
void ensureMemoryBasePathExists(bool createIfNotExistent = false) const; void ensureMemoryBasePathExists(bool createIfNotExistent = false) const;
void ensureFullPathExists(bool createIfNotExistent = false) const; void ensureFullPathExists(bool createIfNotExistent = false) const;
...@@ -72,6 +73,7 @@ namespace armarx::armem::server::ltm::detail::mixin ...@@ -72,6 +73,7 @@ namespace armarx::armem::server::ltm::detail::mixin
private: private:
std::filesystem::path memoryBasePath; std::filesystem::path memoryBasePath;
std::string memoryBasePathString; std::string memoryBasePathString;
std::string pathToHome;
std::string exportName; std::string exportName;
armem::MemoryID _id; 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