Skip to content

Commit

Permalink
Convert PATH_INFO::debug to a cata_path
Browse files Browse the repository at this point in the history
  • Loading branch information
alef committed Dec 29, 2024
1 parent a078529 commit 1dfce02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::ostream> file;
std::string filename;
cata_path filename;
};

// DebugFile OStream Wrapper {{{2
Expand Down Expand Up @@ -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<std::ostringstream> str_buffer = std::dynamic_pointer_cast<std::ostringstream>
( file );
Expand All @@ -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<std::ofstream>(
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();
Expand Down
4 changes: 2 additions & 2 deletions src/path_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/path_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1dfce02

Please sign in to comment.