Check if we're in the process of restarting when trying to open the log

This commit is contained in:
RipleyTom 2019-10-22 16:05:52 +02:00 committed by Megamouse
parent 4599d58413
commit c89ad38ef1
2 changed files with 25 additions and 9 deletions

View file

@ -325,16 +325,25 @@ logs::file_writer::file_writer(const std::string& name)
const std::string log_name = fs::get_cache_dir() + name + ".log";
const std::string buf_name = fs::get_cache_dir() + name + ".buf";
const std::string s_filelock = fs::get_cache_dir() + ".restart_lock";
try
{
if (!m_file.open(buf_name, fs::read + fs::rewrite + fs::lock))
{
#ifdef _WIN32
// Windows does not close all handles before starting a new process with execl
// We delay another check for rpcs3 restart after an update
// TODO: cleaner solution?
std::this_thread::sleep_for(500ms);
if (!m_file.open(buf_name, fs::read + fs::rewrite + fs::lock))
if (fs::exists(s_filelock))
{
// A restart is happening, wait for the file to be accessible
u32 tries = 0;
while (!m_file.open(buf_name, fs::read + fs::rewrite + fs::lock) && tries < 100)
{
std::this_thread::sleep_for(100ms);
tries++;
}
}
if (!m_file)
#endif
{
if (fs::g_tls_error == fs::error::acces)
@ -359,6 +368,10 @@ logs::file_writer::file_writer(const std::string& name)
}
}
#ifdef _WIN32
fs::remove_file(s_filelock); // remove restart token if it exists
#endif
// Check free space
fs::device_stat stats{};
if (!fs::statfs(fs::get_cache_dir(), stats) || stats.avail_free < s_log_size * 8)