Use std filesystem (#3284)

* Use std::filesystem for path names and impl
This commit is contained in:
Gabi Melman
2024-12-05 19:14:25 +02:00
committed by GitHub
parent daf1b97b8f
commit 08c727e4f8
24 changed files with 300 additions and 318 deletions

View File

@@ -7,11 +7,11 @@
#include <mutex>
#include <string>
#include <tuple>
#include <sstream>
#include "spdlog/common.h"
#include "spdlog/details/file_helper.h"
#include "spdlog/details/os.h"
// #include "spdlog/fmt/fmt.h"
namespace spdlog {
namespace sinks {
@@ -51,8 +51,10 @@ filename_t rotating_file_sink<Mutex>::calc_filename(const filename_t &filename,
filename_t basename;
filename_t ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}.{}{}")), basename, index, ext);
std::tie(basename, ext) = details::os::split_by_extension(filename);
std::basic_ostringstream<filename_t::value_type> oss;
oss << basename.native() << '.' << index << ext.native();
return oss.str();
}
template <typename Mutex>
@@ -130,10 +132,8 @@ void rotating_file_sink<Mutex>::rotate_() {
// delete the target if exists, and rename the src file to target
// return true on success, false otherwise.
template <typename Mutex>
bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, const filename_t &target_filename) {
// try to delete the target file in case it already exists.
(void)details::os::remove(target_filename);
return details::os::rename(src_filename, target_filename) == 0;
bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, const filename_t &target_filename) noexcept{
return details::os::rename(src_filename, target_filename);
}
} // namespace sinks