Ticket #3966: t3966_no_empty_simlog_directories_v1.patch
File t3966_no_empty_simlog_directories_v1.patch, 5.3 KB (added by , 8 years ago) |
---|
-
source/lib/file/file_system.h
typedef std::vector<OsPath> DirectoryNam 78 78 79 79 LIB_API Status GetDirectoryEntries(const OsPath& path, CFileInfos* files, DirectoryNames* subdirectoryNames); 80 80 81 81 // same as boost::filesystem::create_directories, except that mkdir is invoked with 82 82 // <mode> instead of 0755. 83 // If the breakpoint is enabled, debug_break will be called if the directory didn't exist and couldn't be created. 83 84 LIB_API Status CreateDirectories(const OsPath& path, mode_t mode, bool breakpoint = true); 84 85 85 86 LIB_API Status DeleteDirectory(const OsPath& dirPath); 86 87 87 88 #endif // #ifndef INCLUDED_FILE_SYSTEM -
source/ps/Replay.cpp
void CReplayLogger::StartGame(JS::Mutabl 68 68 69 69 // Add engine version and currently loaded mods for sanity checks when replaying 70 70 m_ScriptInterface.SetProperty(attribs, "engine_version", CStr(engine_version)); 71 71 m_ScriptInterface.SetProperty(attribs, "mods", g_modsLoaded); 72 72 73 m_Directory = getDateIndexSubdirectory(VisualReplay::GetDirectoryName());73 m_Directory = createDateIndexSubdirectory(VisualReplay::GetDirectoryName()); 74 74 debug_printf("Writing replay to %s\n", m_Directory.string8().c_str()); 75 75 76 76 m_Stream = new std::ofstream(OsString(m_Directory / L"commands.txt").c_str(), std::ofstream::out | std::ofstream::trunc); 77 77 *m_Stream << "start " << m_ScriptInterface.StringifyJSON(attribs, false) << "\n"; 78 78 } -
source/ps/Util.cpp
Status tex_write(Tex* t, const VfsPath& 194 194 } 195 195 196 196 /** 197 197 * Return an unused directory, based on date and index (for example 2016-02-09_0001) 198 198 */ 199 OsPath getDateIndexSubdirectory(const OsPath& parentDir)199 OsPath createDateIndexSubdirectory(const OsPath& parentDir) 200 200 { 201 201 const std::time_t timestamp = std::time(nullptr); 202 202 const struct std::tm* now = std::localtime(×tamp); 203 203 204 204 // Two processes executing this simultaneously might attempt to create the same directory. -
source/ps/Util.h
struct Tex; 24 24 25 25 extern void WriteSystemInfo(); 26 26 27 27 extern const wchar_t* ErrorString(int err); 28 28 29 extern OsPath getDateIndexSubdirectory(const OsPath& parentDir);29 extern OsPath createDateIndexSubdirectory(const OsPath& parentDir); 30 30 31 31 extern void WriteScreenshot(const VfsPath& extension); 32 32 extern void WriteBigScreenshot(const VfsPath& extension, int tiles); 33 33 34 34 extern Status tex_write(Tex* t, const VfsPath& filename); -
source/simulation2/Simulation2.cpp
public: 74 74 { 75 75 CFG_GET_VAL("ooslog", m_EnableOOSLog); 76 76 CFG_GET_VAL("serializationtest", m_EnableSerializationTest); 77 77 } 78 78 79 m_OOSLogPath = getDateIndexSubdirectory(psLogDir() / "oos_logs");80 81 79 if (m_EnableOOSLog) 80 { 81 m_OOSLogPath = createDateIndexSubdirectory(psLogDir() / "oos_logs"); 82 82 debug_printf("Writing ooslogs to %s\n", m_OOSLogPath.string8().c_str()); 83 } 83 84 } 84 85 85 86 ~CSimulation2Impl() 86 87 { 87 88 UnregisterFileReloadFunc(ReloadChangedFileCB, this); … … void CSimulation2Impl::DumpSerialization 294 295 295 296 void CSimulation2Impl::ReportSerializationFailure( 296 297 SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter, 297 298 SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter) 298 299 { 299 const OsPath path = getDateIndexSubdirectory(psLogDir() / "serializationtest");300 const OsPath path = createDateIndexSubdirectory(psLogDir() / "serializationtest"); 300 301 debug_printf("Writing serializationtest-data to %s\n", path.string8().c_str()); 301 302 302 303 // Clean up obsolete files from previous runs 303 304 wunlink(path / "hash.before.a"); 304 305 wunlink(path / "hash.before.b"); … … void CSimulation2Impl::DumpState() 553 554 std::stringstream name;\ 554 555 name << std::setw(5) << std::setfill('0') << m_TurnNumber << ".txt"; 555 556 const OsPath path = m_OOSLogPath / name.str(); 556 557 std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); 557 558 559 if (!DirectoryExists(m_OOSLogPath)) 560 { 561 LOGWARNING("OOS-log directory %s was deleted, creating it again.", m_OOSLogPath.string8().c_str()); 562 CreateDirectories(m_OOSLogPath, 0700); 563 } 564 558 565 file << "State hash: " << std::hex; 559 566 std::string hashRaw; 560 567 m_ComponentManager.ComputeStateHash(hashRaw, false); 561 568 for (size_t i = 0; i < hashRaw.size(); ++i) 562 569 file << std::setfill('0') << std::setw(2) << (int)(unsigned char)hashRaw[i]; … … void CSimulation2::EnableOOSLog() 588 595 { 589 596 if (m->m_EnableOOSLog) 590 597 return; 591 598 592 599 m->m_EnableOOSLog = true; 600 m->m_OOSLogPath = createDateIndexSubdirectory(psLogDir() / "oos_logs"); 601 593 602 debug_printf("Writing ooslogs to %s\n", m->m_OOSLogPath.string8().c_str()); 594 603 } 595 604 596 605 void CSimulation2::EnableSerializationTest() 597 606 {