Files
simple-object-server/src/utils.cpp
Your Name fd6cc5bef4
All checks were successful
Build-Test-Publish / Build (push) Successful in 1m8s
:-'Generic Commit'
2025-05-30 23:46:39 +12:00

38 lines
988 B
C++

#include "utils.hpp"
namespace simple_object_storage
{
ScopeFileDeleter::ScopeFileDeleter(const std::filesystem::path &path) : path_(path), released_(false) {}
ScopeFileDeleter::~ScopeFileDeleter()
{
if (!released_)
{
try
{
if (std::filesystem::exists(path_))
{
std::filesystem::remove(path_);
}
}
catch (const std::filesystem::filesystem_error &e)
{
std::cerr << "Error deleting temp file: " << path_ << " - " << e.what() << std::endl;
}
}
}
void ScopeFileDeleter::release() { released_ = true; }
std::string trim(const std::string &s)
{
size_t start = s.find_first_not_of(" \t\n\r\f\v");
if (start == std::string::npos)
return "";
size_t end = s.find_last_not_of(" \t\n\r\f\v");
return s.substr(start, end - start + 1);
}
}