diff --git a/src/debug.cpp b/src/debug.cpp index 469e8d56f5e0c..4c1e3f004fee9 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -645,14 +645,14 @@ static time_info get_time() noexcept struct DebugFile { DebugFile(); ~DebugFile(); - void init( DebugOutput, const std::string &filename ); + void init( DebugOutput, const cata_path &filename ); void deinit(); std::ostream &get_file(); // Using shared_ptr for the type-erased deleter support, not because // it needs to be shared. std::shared_ptr file; - std::string filename; + cata_path filename; }; // DebugFile OStream Wrapper {{{2 @@ -695,7 +695,7 @@ std::ostream &DebugFile::get_file() return *file; } -void DebugFile::init( DebugOutput output_mode, const std::string &filename ) +void DebugFile::init( DebugOutput output_mode, const cata_path &filename ) { std::shared_ptr str_buffer = std::dynamic_pointer_cast ( file ); @@ -706,17 +706,16 @@ void DebugFile::init( DebugOutput output_mode, const std::string &filename ) break; case DebugOutput::file: { this->filename = filename; - const std::string oldfile = filename + ".prev"; + const cata_path oldfile = filename + ".prev"; bool rename_failed = false; - struct stat buffer; - if( stat( filename.c_str(), &buffer ) == 0 ) { - // Continue with the old log file if it's smaller than 1 MiB - if( buffer.st_size >= 1024 * 1024 ) { - rename_failed = !rename_file( filename, oldfile ); - } + // Continue with the old log file if it's smaller than 1 MiB + if (fs::file_size(fs::path(filename)) >= 1024 * 1024) { + std::error_code ec; + fs::rename(fs::path(filename), fs::path(oldfile), ec); + rename_failed = bool(ec); } file = std::make_shared( - fs::u8path( filename ), std::ios::out | std::ios::app ); + filename.generic_u8string(), std::ios::out | std::ios::app ); *file << "\n\n-----------------------------------------\n"; *file << get_time() << " : Starting log."; DebugLog( D_INFO, D_MAIN ) << "Cataclysm DDA version " << getVersionString(); diff --git a/src/path_info.cpp b/src/path_info.cpp index bea276a06918e..c1bfe3b662f58 100644 --- a/src/path_info.cpp +++ b/src/path_info.cpp @@ -263,9 +263,9 @@ cata_path PATH_INFO::datadir_path() { return datadir_path_value; } -std::string PATH_INFO::debug() +cata_path PATH_INFO::debug() { - return config_dir_value + "debug.log"; + return config_dir_path_value / "debug.log"; } cata_path PATH_INFO::defaultsounddir() { diff --git a/src/path_info.h b/src/path_info.h index 3fb46268b3f66..dc573eb1b47ec 100644 --- a/src/path_info.h +++ b/src/path_info.h @@ -25,7 +25,6 @@ void set_standard_filenames(); std::string cache_dir(); std::string config_dir(); std::string datadir(); -std::string debug(); std::string defaulttilejson(); std::string defaultlayeringjson(); std::string defaulttilepng(); @@ -62,6 +61,7 @@ cata_path config_dir_path(); cata_path custom_colors(); cata_path data_sound(); cata_path datadir_path(); +cata_path debug(); cata_path defaultsounddir(); cata_path fontdata(); cata_path gfxdir();