From 37459ae9f1e016c3071b5693a127ba1357dbe4e2 Mon Sep 17 00:00:00 2001 From: Arnaud Kapp Date: Wed, 12 Nov 2014 23:25:00 +0100 Subject: [PATCH] Check return code from std::remove. In case removing a file (file_sink) fails, we throw spdlog_ex. --- include/spdlog/sinks/file_sinks.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index ee773e59..847af960 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -125,14 +125,22 @@ private: std::string target = calc_filename(_base_filename, i, _extension); 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())) { throw spdlog_ex("rotating_file_sink: failed renaming " + src + " to " + target); } } 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); } std::string _base_filename;