|
@@ -517,6 +517,9 @@ void ResourceWatcherFSM::TriggerAtStatusChanged(bool bMStatus)
|
|
|
GetEntityBase()->GetFunction()->SetTimer(TIMER_DISK_CHECK, pListener2, diskCheckTime);
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set DISK CHECK Timer!");
|
|
|
|
|
|
+ DeleteFileTask* deleteFilesTask = new DeleteFileTask(this);
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(deleteFilesTask);
|
|
|
+
|
|
|
#if defined(RVC_OS_LINUX)
|
|
|
if (m_bFirstRunAfterBoot) {
|
|
|
UINT sysVer = 0;
|
|
@@ -1762,6 +1765,130 @@ bool ResourceWatcherFSM::IsNeedToFirstClear()
|
|
|
#endif // RVC_OS_LINUX
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherFSM::DeleteFiles()
|
|
|
+{
|
|
|
+ string p;
|
|
|
+ CSmartPointer<IConfigInfo> spCtSettingConfig;
|
|
|
+ GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
|
|
|
+ CSimpleStringA upPath(""), tempPath(""), tPath(""), upgradePath("");
|
|
|
+ spCtSettingConfig->ReadConfigValue("ResourceWatcher", "DocumentCleanPath", tempPath);
|
|
|
+ if (tempPath.GetLength() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ErrorCodeEnum erroCode = Error_Succeed;
|
|
|
+ CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
|
|
|
+ CSmartPointer<IConfigInfo> spConfigRun;
|
|
|
+ //判断是否需要被清理
|
|
|
+ erroCode = pFunc->OpenConfig(Config_Run, spConfigRun);
|
|
|
+ if (erroCode != Error_Succeed) {
|
|
|
+ LogWarn(Severity_Middle, erroCode, 0, "Open Run Config failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int nLastTaskTime = 0;
|
|
|
+ int nLstFlag = 0;
|
|
|
+ bool bFailFlag = false;
|
|
|
+ CSimpleStringA optFileName("");
|
|
|
+ UINT64 utVersion = 0;
|
|
|
+
|
|
|
+ spConfigRun->ReadConfigValueHexInt("DeleteDocumentTask", "OptVer", utVersion);
|
|
|
+ spConfigRun->ReadConfigValue("DeleteDocumentTask", "DocumentName", optFileName);
|
|
|
+ spConfigRun->ReadConfigValueInt("DeleteDocumentTask", "LastCondi", nLstFlag);
|
|
|
+ spConfigRun->ReadConfigValueInt("DeleteDocumentTask", "LastTime", nLastTaskTime);
|
|
|
+
|
|
|
+ CVersion optVer(utVersion);
|
|
|
+ SYSTEMTIME stTaskTime = CSmallDateTime(nLastTaskTime).ToSystemTime();
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("LastTime<%04d-%02d-%02d %02d:%02d:%02d>: OptVer: %s, LastCondi: %d",
|
|
|
+ stTaskTime.wYear, stTaskTime.wMonth, stTaskTime.wDay,
|
|
|
+ stTaskTime.wHour, stTaskTime.wMinute, stTaskTime.wSecond,
|
|
|
+ (LPCTSTR)optVer.ToString(), nLstFlag);
|
|
|
+ if (optVer.IsValid() && optVer == m_RvcSysinfo.InstallVersion && !nLstFlag && optFileName == tempPath)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Certain document cleaning has been done before.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ //删除upPath目录下的文件
|
|
|
+ struct _finddata_t upfileinfo;
|
|
|
+ long upFile = 0;
|
|
|
+
|
|
|
+ WIN32_FIND_DATA wfd;
|
|
|
+ HANDLE hFind;
|
|
|
+
|
|
|
+ upPath = tempPath;
|
|
|
+ upPath.Append("\\*");
|
|
|
+ hFind = FindFirstFile(upPath.GetData(), &wfd);
|
|
|
+ if (hFind != INVALID_HANDLE_VALUE) {
|
|
|
+ if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
+ int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
|
|
|
+ nFileCount = ProcessFileDelete(upPath.GetData(), nDelSuc, nDelFail);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Process result(%s): count(%d), suc(%d), failed(%d).", upPath.GetData(), nFileCount, nDelSuc, nDelFail);
|
|
|
+ if (nDelFail != 0) {
|
|
|
+ bFailFlag = true;
|
|
|
+ //break;
|
|
|
+ }
|
|
|
+ FindClose(hFind);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (DeleteFile(tempPath.GetData()) != 0) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("删除文件%s成功。", tempPath.GetData());
|
|
|
+ //break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bFailFlag = true;
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("删除文件%s失败。", tempPath.GetData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("FindFirstFile failed (%s)(%u)", upPath.GetData(), GetLastError());
|
|
|
+ }
|
|
|
+#else //LINUX
|
|
|
+ struct stat buffer;
|
|
|
+ upPath = tempPath;
|
|
|
+ if (stat(upPath.GetData(), &buffer) == 0 && S_ISDIR(buffer.st_mode)) //判断是不是文件夹
|
|
|
+ {
|
|
|
+ int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
|
|
|
+ nFileCount = ProcessFileDelete(upPath.GetData(), nDelSuc, nDelFail);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Process result(%s): count(%d), suc(%d), failed(%d).", upPath.GetData(), nFileCount, nDelSuc, nDelFail);
|
|
|
+ if (nDelFail != 0) {
|
|
|
+ bFailFlag = true;
|
|
|
+ //break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (RemoveFileA(tempPath.GetData()) != 0) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("删除文件%s成功。", tempPath.GetData());
|
|
|
+ //break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bFailFlag = true;
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("删除文件%s失败。", tempPath.GetData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+
|
|
|
+ nLstFlag = bFailFlag ? 1 : 0;
|
|
|
+ spConfigRun->WriteConfigValueHexInt("DeleteDocumentTask", "OptVer", m_RvcSysinfo.InstallVersion.GetVersion64());
|
|
|
+ spConfigRun->WriteConfigValue("DeleteDocumentTask", "DocumentName", tempPath);
|
|
|
+ spConfigRun->WriteConfigValueInt("DeleteDocumentTask", "LastCondi", nLstFlag);
|
|
|
+ spConfigRun->WriteConfigValue("DeleteDocumentTask", "LastTime",
|
|
|
+ (LPCTSTR)CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
|
|
|
+
|
|
|
+ if (!bFailFlag) {
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_DIR_DELETE, CSimpleStringA::Format("Delete files in [%s] success", tempPath.GetData()));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete files in [%s] failed.", tempPath.GetData());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt)
|
|
|
{
|
|
|
#ifdef RVC_OS_LINUX
|
|
@@ -3978,106 +4105,6 @@ bool ResourceWatcherFSM::VerifyOtherCertificate(PCMSG_SIGNER_INFO pSignerInfo)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-void ResourceWatcherFSM::DeleteFiles()
|
|
|
-{
|
|
|
- string p;
|
|
|
- CSmartPointer<IConfigInfo> spCtSettingConfig;
|
|
|
- GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
|
|
|
- CSimpleStringA upPath(""), tempPath(""), tPath(""), upgradePath("");
|
|
|
- spCtSettingConfig->ReadConfigValue("ResourceWatcher", "DocumentCleanPath", tempPath);
|
|
|
- if (tempPath.GetLength() == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- ErrorCodeEnum erroCode = Error_Succeed;
|
|
|
- CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
|
|
|
- CSmartPointer<IConfigInfo> spConfigRun;
|
|
|
- //判断是否需要被清理
|
|
|
- erroCode = pFunc->OpenConfig(Config_Run, spConfigRun);
|
|
|
- if (erroCode != Error_Succeed) {
|
|
|
- LogWarn(Severity_Middle, erroCode, 0, "Open Run Config failed");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- int nLastTaskTime = 0;
|
|
|
- int nLstFlag = 0;
|
|
|
- CSimpleStringA optFileName("");
|
|
|
- UINT64 utVersion = 0;
|
|
|
-
|
|
|
- spConfigRun->ReadConfigValueHexInt("DeleteDocumentTask", "OptVer", utVersion);
|
|
|
- spConfigRun->ReadConfigValue("DeleteDocumentTask", "DocumentName", optFileName);
|
|
|
- spConfigRun->ReadConfigValueInt("DeleteDocumentTask", "LastCondi", nLstFlag);
|
|
|
- spConfigRun->ReadConfigValueInt("DeleteDocumentTask", "LastTime", nLastTaskTime);
|
|
|
-
|
|
|
- CVersion optVer(utVersion);
|
|
|
- SYSTEMTIME stTaskTime = CSmallDateTime(nLastTaskTime).ToSystemTime();
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("LastTime<%04d-%02d-%02d %02d:%02d:%02d>: OptVer: %s, LastCondi: %d",
|
|
|
- stTaskTime.wYear, stTaskTime.wMonth, stTaskTime.wDay,
|
|
|
- stTaskTime.wHour, stTaskTime.wMinute, stTaskTime.wSecond,
|
|
|
- (LPCTSTR)optVer.ToString(), nLstFlag);
|
|
|
- SYSTEMTIME stNow = {};
|
|
|
- GetLocalTime(&stNow);
|
|
|
- if (optVer.IsValid() && optVer == m_RvcSysinfo.InstallVersion && !nLstFlag && optFileName == tempPath)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Certain document cleaning has been done before.");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //删除upPath目录下的文件
|
|
|
- struct _finddata_t upfileinfo;
|
|
|
- long upFile = 0;
|
|
|
- bool bFailFlag = false;
|
|
|
-
|
|
|
- WIN32_FIND_DATA wfd;
|
|
|
- HANDLE hFind;
|
|
|
-
|
|
|
- upPath = tempPath;
|
|
|
- upPath.Append("\\*");
|
|
|
- hFind = FindFirstFile(upPath.GetData(), &wfd);
|
|
|
- if (hFind != INVALID_HANDLE_VALUE) {
|
|
|
- if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
- int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
|
|
|
- nFileCount = ProcessFileDelete(upPath.GetData(), nDelSuc, nDelFail);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Process result(%s): count(%d), suc(%d), failed(%d).", upPath.GetData(), nFileCount, nDelSuc, nDelFail);
|
|
|
- if (nDelFail != 0) {
|
|
|
- bFailFlag = true;
|
|
|
- //break;
|
|
|
- }
|
|
|
- FindClose(hFind);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (DeleteFile(tempPath.GetData()) != 0) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("删除文件%s成功。", tempPath.GetData());
|
|
|
- //break;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- bFailFlag = true;
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("删除文件%s失败。", tempPath.GetData());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("FindFirstFile failed (%s)(%u)", upPath.GetData(), GetLastError());
|
|
|
- }
|
|
|
-
|
|
|
- nLstFlag = bFailFlag ? 1 : 0;
|
|
|
- spConfigRun->WriteConfigValueHexInt("DeleteDocumentTask", "OptVer", m_RvcSysinfo.InstallVersion.GetVersion64());
|
|
|
- spConfigRun->WriteConfigValue("DeleteDocumentTask", "DocumentName", tempPath);
|
|
|
- spConfigRun->WriteConfigValueInt("DeleteDocumentTask", "LastCondi", nLstFlag);
|
|
|
- spConfigRun->WriteConfigValue("DeleteDocumentTask", "LastTime",
|
|
|
- (LPCTSTR)CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
|
|
|
-
|
|
|
- if (!bFailFlag) {
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_WARN_DIR_DELETE, CSimpleStringA::Format("Delete files in [%s] success", tempPath.GetData()));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete files in [%s] failed.", tempPath.GetData());
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
void ResourceWatcherFSM::ClearDumpFiles()
|
|
|
{
|
|
|
int deleteSucCnt = 0;
|
|
@@ -5083,7 +5110,7 @@ void ResourceWatcherFSM::CheckDiskFileSpace()
|
|
|
CSimpleStringA warnMsg(true);
|
|
|
while (fgets(buf, sizeof(buf), fp))
|
|
|
{
|
|
|
- warnMsg = warnMsg + buf + "\n";
|
|
|
+ warnMsg = warnMsg + "|" + buf;
|
|
|
}
|
|
|
if (warnMsg.GetLength() > 0)
|
|
|
{
|
|
@@ -5103,7 +5130,7 @@ void ResourceWatcherFSM::CheckDiskFileSpace()
|
|
|
char buf2[1024] = { 0 };
|
|
|
while (fgets(buf2, sizeof(buf2), fp2))
|
|
|
{
|
|
|
- warnMsg2 = warnMsg2 + buf2 + "\n";
|
|
|
+ warnMsg2 = warnMsg2 + "|" + buf2;
|
|
|
}
|
|
|
if (warnMsg2.GetLength() > 0)
|
|
|
{
|