Ticket #3966: t3966_no_empty_simlog_directories_v1.patch

File t3966_no_empty_simlog_directories_v1.patch, 5.3 KB (added by elexis, 8 years ago)
  • source/lib/file/file_system.h

    typedef std::vector<OsPath> DirectoryNam  
    7878
    7979LIB_API Status GetDirectoryEntries(const OsPath& path, CFileInfos* files, DirectoryNames* subdirectoryNames);
    8080
    8181// same as boost::filesystem::create_directories, except that mkdir is invoked with
    8282// <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.
    8384LIB_API Status CreateDirectories(const OsPath& path, mode_t mode, bool breakpoint = true);
    8485
    8586LIB_API Status DeleteDirectory(const OsPath& dirPath);
    8687
    8788#endif  // #ifndef INCLUDED_FILE_SYSTEM
  • source/ps/Replay.cpp

    void CReplayLogger::StartGame(JS::Mutabl  
    6868
    6969    // Add engine version and currently loaded mods for sanity checks when replaying
    7070    m_ScriptInterface.SetProperty(attribs, "engine_version", CStr(engine_version));
    7171    m_ScriptInterface.SetProperty(attribs, "mods", g_modsLoaded);
    7272
    73     m_Directory = getDateIndexSubdirectory(VisualReplay::GetDirectoryName());
     73    m_Directory = createDateIndexSubdirectory(VisualReplay::GetDirectoryName());
    7474    debug_printf("Writing replay to %s\n", m_Directory.string8().c_str());
    7575
    7676    m_Stream = new std::ofstream(OsString(m_Directory / L"commands.txt").c_str(), std::ofstream::out | std::ofstream::trunc);
    7777    *m_Stream << "start " << m_ScriptInterface.StringifyJSON(attribs, false) << "\n";
    7878}
  • source/ps/Util.cpp

    Status tex_write(Tex* t, const VfsPath&  
    194194}
    195195
    196196/**
    197197 * Return an unused directory, based on date and index (for example 2016-02-09_0001)
    198198 */
    199 OsPath getDateIndexSubdirectory(const OsPath& parentDir)
     199OsPath createDateIndexSubdirectory(const OsPath& parentDir)
    200200{
    201201    const std::time_t timestamp = std::time(nullptr);
    202202    const struct std::tm* now = std::localtime(&timestamp);
    203203
    204204    // Two processes executing this simultaneously might attempt to create the same directory.
  • source/ps/Util.h

    struct Tex;  
    2424
    2525extern void WriteSystemInfo();
    2626
    2727extern const wchar_t* ErrorString(int err);
    2828
    29 extern OsPath getDateIndexSubdirectory(const OsPath& parentDir);
     29extern OsPath createDateIndexSubdirectory(const OsPath& parentDir);
    3030
    3131extern void WriteScreenshot(const VfsPath& extension);
    3232extern void WriteBigScreenshot(const VfsPath& extension, int tiles);
    3333
    3434extern Status tex_write(Tex* t, const VfsPath& filename);
  • source/simulation2/Simulation2.cpp

    public:  
    7474        {
    7575            CFG_GET_VAL("ooslog", m_EnableOOSLog);
    7676            CFG_GET_VAL("serializationtest", m_EnableSerializationTest);
    7777        }
    7878
    79         m_OOSLogPath = getDateIndexSubdirectory(psLogDir() / "oos_logs");
    80 
    8179        if (m_EnableOOSLog)
     80        {
     81            m_OOSLogPath = createDateIndexSubdirectory(psLogDir() / "oos_logs");
    8282            debug_printf("Writing ooslogs to %s\n", m_OOSLogPath.string8().c_str());
     83        }
    8384    }
    8485
    8586    ~CSimulation2Impl()
    8687    {
    8788        UnregisterFileReloadFunc(ReloadChangedFileCB, this);
    void CSimulation2Impl::DumpSerialization  
    294295
    295296void CSimulation2Impl::ReportSerializationFailure(
    296297    SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter,
    297298    SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter)
    298299{
    299     const OsPath path = getDateIndexSubdirectory(psLogDir() / "serializationtest");
     300    const OsPath path = createDateIndexSubdirectory(psLogDir() / "serializationtest");
    300301    debug_printf("Writing serializationtest-data to %s\n", path.string8().c_str());
    301302
    302303    // Clean up obsolete files from previous runs
    303304    wunlink(path / "hash.before.a");
    304305    wunlink(path / "hash.before.b");
    void CSimulation2Impl::DumpState()  
    553554    std::stringstream name;\
    554555    name << std::setw(5) << std::setfill('0') << m_TurnNumber << ".txt";
    555556    const OsPath path = m_OOSLogPath / name.str();
    556557    std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);
    557558
     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
    558565    file << "State hash: " << std::hex;
    559566    std::string hashRaw;
    560567    m_ComponentManager.ComputeStateHash(hashRaw, false);
    561568    for (size_t i = 0; i < hashRaw.size(); ++i)
    562569        file << std::setfill('0') << std::setw(2) << (int)(unsigned char)hashRaw[i];
    void CSimulation2::EnableOOSLog()  
    588595{
    589596    if (m->m_EnableOOSLog)
    590597        return;
    591598
    592599    m->m_EnableOOSLog = true;
     600    m->m_OOSLogPath = createDateIndexSubdirectory(psLogDir() / "oos_logs");
     601
    593602    debug_printf("Writing ooslogs to %s\n", m->m_OOSLogPath.string8().c_str());
    594603}
    595604
    596605void CSimulation2::EnableSerializationTest()
    597606{