Commit 37459ae9 authored by Arnaud Kapp's avatar Arnaud Kapp

Check return code from std::remove.

In case removing a file (file_sink) fails, we throw spdlog_ex.
parent 1008f569
...@@ -125,14 +125,22 @@ private: ...@@ -125,14 +125,22 @@ private:
std::string target = calc_filename(_base_filename, i, _extension); std::string target = calc_filename(_base_filename, i, _extension);
if (details::file_helper::file_exists(target)) if (details::file_helper::file_exists(target))
std::remove(target.c_str()); {
if (std::remove(target.c_str()) != 0)
{
throw spdlog_ex("rotating_file_sink: failed removing " + target);
}
}
if (details::file_helper::file_exists(src) && std::rename(src.c_str(), target.c_str())) if (details::file_helper::file_exists(src) && std::rename(src.c_str(), target.c_str()))
{ {
throw spdlog_ex("rotating_file_sink: failed renaming " + src + " to " + target); throw spdlog_ex("rotating_file_sink: failed renaming " + src + " to " + target);
} }
} }
auto cur_name = _file_helper.filename(); auto cur_name = _file_helper.filename();
std::remove(cur_name.c_str()); if (std::remove(cur_name.c_str()) != 0)
{
throw spdlog_ex("rotating_file_sink: failed removing " + cur_name);
}
_file_helper.open(cur_name); _file_helper.open(cur_name);
} }
std::string _base_filename; std::string _base_filename;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment