@@ -51,6 +51,7 @@ bool CDatabase_Memory::Database_Memory_Init(list<XENGINE_STORAGEBUCKET>* pStl_Li
5151 Database_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_INIT_THREAD;
5252 return false ;
5353 }
54+ m_nHashMode = nHashMode;
5455 stl_ListBucket = *pStl_ListBucket;
5556 return true ;
5657}
@@ -256,11 +257,19 @@ bool CDatabase_Memory::Database_Memory_Flush()
256257{
257258 Database_IsErrorOccur = false ;
258259
260+ st_Locker->lock ();
261+ stl_ListFile.clear ();
259262 for (auto stl_ListIterator = stl_ListBucket.begin (); stl_ListIterator != stl_ListBucket.end (); stl_ListIterator++)
260263 {
261264 int nListCount = 0 ;
262265 XCHAR** pptszListFile;
263- SystemApi_File_EnumFile (stl_ListIterator->tszFilePath , &pptszListFile, &nListCount, NULL , NULL , true , 1 );
266+ XCHAR tszFoundDir[MAX_PATH];
267+
268+ memset (tszFoundDir, ' \0 ' , MAX_PATH);
269+ _tcsxcpy (tszFoundDir, stl_ListIterator->tszFilePath );
270+ _tcsxcat (tszFoundDir, _T (" /*" ));
271+
272+ SystemApi_File_EnumFile (tszFoundDir, &pptszListFile, &nListCount, NULL , NULL , true , 1 );
264273 for (int i = 0 ; i < nListCount; i++)
265274 {
266275 int nHashLen = 0 ;
@@ -272,17 +281,21 @@ bool CDatabase_Memory::Database_Memory_Flush()
272281 memset (&st_DBFile, ' \0 ' , sizeof (XSTORAGECORE_DBFILE));
273282
274283 _xtstat (pptszListFile[i], &st_FileStatus);
275- st_DBFile.st_ProtocolFile .nFileSize = st_FileStatus.st_size ;
284+
285+ if (st_FileStatus.st_size > 0 )
286+ {
287+ st_DBFile.st_ProtocolFile .nFileSize = st_FileStatus.st_size ;
288+ OPenSsl_Api_Digest (pptszListFile[i], tszHashStr, &nHashLen, true , m_nHashMode);
289+ BaseLib_OperatorString_StrToHex ((char *)tszHashStr, nHashLen, st_DBFile.st_ProtocolFile .tszFileHash );
290+ BaseLib_OperatorString_GetFileAndPath (pptszListFile[i], st_DBFile.st_ProtocolFile .tszFilePath , st_DBFile.st_ProtocolFile .tszFileName );
291+ _tcsxcpy (st_DBFile.tszBuckKey , stl_ListIterator->tszBuckKey );
276292
277- OPenSsl_Api_Digest (pptszListFile[i], tszHashStr, &nHashLen, true , m_nHashMode);
278- BaseLib_OperatorString_StrToHex ((char *)tszHashStr, nHashLen, st_DBFile.st_ProtocolFile .tszFileHash );
279- BaseLib_OperatorString_GetFileAndPath (pptszListFile[i], st_DBFile.st_ProtocolFile .tszFilePath , st_DBFile.st_ProtocolFile .tszFileName );
280- _tcsxcpy (st_DBFile.tszBuckKey , stl_ListIterator->tszBuckKey );
281-
282- stl_ListFile.push_back (st_DBFile);
293+ stl_ListFile.push_back (st_DBFile);
294+ }
283295 }
284296 BaseLib_OperatorMemory_Free ((XPPPMEM)&pptszListFile, nListCount);
285297 }
298+ st_Locker->unlock ();
286299 return true ;
287300}
288301// ////////////////////////////////////////////////////////////////////////
@@ -293,15 +306,16 @@ XHTHREAD CDatabase_Memory::Database_Memory_Thread(XPVOID lParam)
293306 CDatabase_Memory *pClass_This = (CDatabase_Memory *)lParam;
294307 time_t nTimeStart = time (NULL );
295308 time_t nTimeEnd = 0 ;
296- int nTime = 60 * 60 * 12 ;
309+ int nTime = 60 ;
297310
298311 while (pClass_This->m_bIsRun )
299312 {
313+ nTimeEnd = time (NULL );
300314 if ((nTimeEnd - nTimeStart) > nTime)
301315 {
316+ nTimeStart = nTimeEnd;
302317 pClass_This->Database_Memory_Flush ();
303318 }
304- nTimeEnd = time (NULL );
305319 std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
306320 }
307321 return 0 ;
0 commit comments