Ver código fonte

#IQRV #comment: 去除运行时文件的记录,对不同删除线程用不同RTA错误码记录

陈纪林80310970 7 meses atrás
pai
commit
4f027abe21

+ 16 - 125
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -540,9 +540,9 @@ void ResourceWatcherFSM::CenterSettingDelete()
     CSmartPointer<IConfigInfo> spCtSettingConfig;
     GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
     CSimpleStringA upPath(""), tempPath(""), tPath("");
-    int delDirFlag = 0, backDay = 0;
+    int closeRmDir = 0, backDay = 0;
     spCtSettingConfig->ReadConfigValue("ResourceWatcher", "DocumentCleanPath", tempPath);
-    spCtSettingConfig->ReadConfigValueInt("ResourceWatcher", "DocumentCleanRmvDirFlag", delDirFlag);
+    spCtSettingConfig->ReadConfigValueInt("ResourceWatcher", "DocumentCleanCloseRmDir", closeRmDir);
     spCtSettingConfig->ReadConfigValueInt("ResourceWatcher", "DocumentCleanBackDay", backDay);
     if (tempPath.GetLength() == 0) {
         return;
@@ -550,53 +550,19 @@ void ResourceWatcherFSM::CenterSettingDelete()
     ErrorCodeEnum erroCode = Error_Succeed;
     CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
     CSmartPointer<IConfigInfo> spConfigRun;
-    //判断是否需要被清理
-    erroCode = pFunc->OpenConfig(Config_Run, spConfigRun);
-    if (erroCode != Error_Succeed) {
-        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("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_INFO, LOG_TYPE_SYSTEM)("Certain document cleaning has been done before.");
-        return;
-    }
 
     //执行清理逻辑
+    bool delDir = (closeRmDir == 0) ? true : false;
     upPath = tempPath;
     int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
-    nFileCount = ProcessFileDelete(upPath.GetData(), nDelSuc, nDelFail, delDirFlag, backDay);
+    nFileCount = ProcessFileDelete("RTA5A14", upPath.GetData(), nDelSuc, nDelFail, delDir, backDay);
     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;
     }
 
-    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_FILE_DELETE_SUC, CSimpleStringA::Format("Delete files in [%s] success", tempPath.GetData()));
@@ -645,7 +611,7 @@ time_t ResourceWatcherFSM::GetPathTimeSeconds(const char* inPath)
 //所有文件删除功能都用这个函数来处理 
 //bool delDir:控制是否将目录也一并删除,false 保留目录, true 删除目录
 //int saveBackDay:保存多少天内的文件, 默认参数,默认值为0,即不保存。(delDir = true时,该参数强制为0)
-int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt, bool delDir, unsigned int saveBackDay)
+int ResourceWatcherFSM::ProcessFileDelete(CSimpleStringA rtaCode, LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt, bool delDir, unsigned int saveBackDay)
 {
     int fileCnt = 0;
     if (delDir == true) //若要删除目录,则不保留任何文件
@@ -656,7 +622,7 @@ int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int
         if (!deleteDir)
         {
             CSimpleStringA errMsg = CSimpleStringA::Format("RemovePath [%s] failed, GLE = %u.", lpszPath, GetLastError());
-            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A08").setAPI("DeleteFiles")(errMsg.GetData());
+            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(rtaCode.GetData()).setAPI("DeleteFiles")(errMsg.GetData());
             LogWarn(Severity_Middle, Error_Debug, LOG_WARN_FILE_DELETE_FAILED, errMsg.GetData());
             nDelFailedCnt++;
         }
@@ -703,7 +669,7 @@ int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int
                 }
 
                 int tDelSucCnt = 0, tDelFailedCnt = 0;
-                fileCnt += ProcessFileDelete(tmp, tDelSucCnt, tDelFailedCnt, delSubDir, saveBackDay); //子目录递归处理
+                fileCnt += ProcessFileDelete(rtaCode, tmp, tDelSucCnt, tDelFailedCnt, delSubDir, saveBackDay); //子目录递归处理
                 nDelFailedCnt += tDelFailedCnt;
                 nDelSucCnt += tDelSucCnt;
             }
@@ -716,7 +682,7 @@ int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int
             for (i = 0; i < arr->nelts; ++i) {
                 char* tmp = ARRAY_IDX(arr, i, char*);
                 int tDelSucCnt = 0, tDelFailedCnt = 0;
-                fileCnt += ProcessFileDelete(tmp, tDelSucCnt, tDelFailedCnt, delDir, saveBackDay); //子目录递归处理
+                fileCnt += ProcessFileDelete(rtaCode, tmp, tDelSucCnt, tDelFailedCnt, delDir, saveBackDay); //子目录递归处理
                 nDelFailedCnt += tDelFailedCnt;
                 nDelSucCnt += tDelSucCnt;
             }
@@ -752,7 +718,7 @@ int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int
         {
             nDelFailedCnt++;
             CSimpleStringA errMsg = CSimpleStringA::Format("RemoveFileA [%s] failed, GLE = %u.", lpszPath, GetLastError());
-            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA5A08").setAPI("DeleteFiles")(errMsg.GetData());
+            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(rtaCode.GetData()).setAPI("DeleteFiles")(errMsg.GetData());
             LogWarn(Severity_Middle, Error_Debug, LOG_WARN_FILE_DELETE_FAILED, errMsg.GetData());
         }
         return fileCnt;
@@ -794,7 +760,7 @@ void ResourceWatcherFSM::AutoDeleteFiles()
 
 }
 
-//终端升级后会执行版本清理功能 包含dump和 upgaraded清理
+//终端升级后会执行版本清理功能
 BOOL ResourceWatcherFSM::DeleteVersionPackage()
 {
     ErrorCodeEnum erroCode = Error_Succeed;
@@ -807,74 +773,6 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
         return FALSE;
     }
 
-    //清理执行成功与否的判断变量
-    int nLastTaskTime = 0;
-    int nLstFailed = 0;
-    int nDelCount = 0;
-    UINT64 utVersion = 0;
-
-    pFunc->OpenConfig(Config_CenterSetting, spConfig);
-    pFunc->OpenConfig(Config_Run, spConfigRun);
-
-    spConfigRun->ReadConfigValueHexInt("VersionClear", "OptVer", utVersion);
-    spConfigRun->ReadConfigValueInt("VersionClear", "DelVerCnt", nDelCount);
-    spConfigRun->ReadConfigValueInt("VersionClear", "LastCondi", nLstFailed); //失败标志
-    spConfigRun->ReadConfigValueInt("VersionClear", "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, LastFailed: %d",
-        stTaskTime.wYear, stTaskTime.wMonth, stTaskTime.wDay,
-        stTaskTime.wHour, stTaskTime.wMinute, stTaskTime.wSecond,
-        (LPCTSTR)optVer.ToString(), nLstFailed);
-    
-    //判断是否需要执行清理任务,若此版本之前成功清理过则不再继续执行后续操作
-    if (optVer.IsValid() && optVer == info.InstallVersion && !nLstFailed) {
-        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("VersionPackage cleaning has been done before.");
-        return TRUE;
-    }
-
-    //--------------------------------------------------------------------------------------------
-    //版本清理中默认进行upgrade清理
-    int closeUpgradeClear = 0;
-    spConfig->ReadConfigValueInt("ResourceWatcher", "CloseUpgradeClear", closeUpgradeClear);
-    if (!closeUpgradeClear)
-    {
-        //删除rvc/Upgraded目录下的文件 
-        CSimpleStringA upPath;
-        ErrorCodeEnum upError = pFunc->GetPath("Upgraded", upPath);
-        if (Error_Succeed != upError) {
-            DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Try to clean Upgraded Dir. But get Upgraded path error = %u.", upError);
-            return FALSE;
-        }
-        int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
-        nFileCount = ProcessFileDelete(upPath.GetData(), nDelSuc, nDelFail, false);
-        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete [Upgraded] result(%s): count(%d), suc(%d), failed(%d).", upPath.GetData(), nFileCount, nDelSuc, nDelFail);
-    }
-
-    //--------------------------------------------------------------------------------------------
-    //版本清理中默认进行dump清理
-    int closeDmpClear = 0;
-    spConfig->ReadConfigValueInt("ResourceWatcher", "CloseDmpClear", closeDmpClear);
-    if (!closeDmpClear)
-    {    //执行删除流程rvc/dmp
-        CSimpleStringA dmpPath;
-        ErrorCodeEnum dmpError = pFunc->GetPath("Temp", dmpPath);
-        if (Error_Succeed != dmpError) {
-            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Try to clean Dump Dir. But get Temp path error = %u.", dmpError);
-            return FALSE;
-        }
-#ifdef RVC_OS_LINUX
-        dmpPath = dmpPath + SPLIT_SLASH_STR + ".." + SPLIT_SLASH_STR + "dmp"; // +"/../dmp"
-#else
-        dmpPath = dmpPath + CSimpleStringA::Format("\\..\\dmp");
-#endif // RVC_OS_LINUX
-
-        int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
-        nFileCount = ProcessFileDelete(dmpPath.GetData(), nDelSuc, nDelFail, false);
-        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete [Dump] result(%s): count(%d), suc(%d), failed(%d).", dmpPath.GetData(), nFileCount, nDelSuc, nDelFail);
-    }
-
     //--------------------------------------------------------------------------------------------
     //清理ver文件夹
     int closeVerClear = 0;
@@ -926,7 +824,7 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
                 int n = sscanf(dirp->d_name, "%d.%d.%d.%d", &dwMajor, &dwMinor, &dwRevision, &dwBuild);
                 if (n != 4)
                 {
-                    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not version file.[%s]", dirp->d_name);
+                    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not target version file.[%s]", dirp->d_name);
                     continue;
                 }
                 else {
@@ -940,7 +838,7 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
                         intallInfoVects.push_back(verName);
                     }
                     else {
-                        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not version file.[%s]", dirp->d_name);
+                        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not target version file.[%s]", dirp->d_name);
                     }
                 }
             }
@@ -958,7 +856,7 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
                 int n = sscanf(fileinfo.name, "%d.%d.%d.%d", &dwMajor, &dwMinor, &dwRevision, &dwBuild);
                 if (n != 4)
                 {
-                    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not version file.[%s]", fileinfo.name);
+                    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not target version file.[%s]", fileinfo.name);
                     continue;
                 }
                 else {
@@ -973,7 +871,7 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
                         intallInfoVects.push_back(verName);
                     }
                     else {
-                        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not version file.[%s]", fileinfo.name);
+                        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not target version file.[%s]", fileinfo.name);
                     }
                 }
             } while (_findnext(hFile, &fileinfo) == 0);
@@ -1020,7 +918,7 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
 #else
                 tVerPath = verPath + "\\" + (*riter).ToString();
 #endif // RVC_OS_LINUX
-                nFileCount = ProcessFileDelete(tVerPath.GetData(), nDelSuc, nDelFail, true); //版本文件夹连目录一起清理
+                nFileCount = ProcessFileDelete("RTA5A12", tVerPath.GetData(), nDelSuc, nDelFail, true); //版本文件夹连目录一起清理
                 DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete Version result(%s): count(%d), suc(%d), failed(%d).", 
                     tVerPath.GetData(), nFileCount, nDelSuc, nDelFail);
                 if (nDelFail)
@@ -1036,13 +934,6 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
             }
         }
 
-        nLstFailed = bFailFlag ? 1 : 0;
-        spConfigRun->WriteConfigValueHexInt("VersionClear", "OptVer", info.InstallVersion.GetVersion64());
-        spConfigRun->WriteConfigValueInt("VersionClear", "DelVerCnt", nDelCount + nDelVersionCnt);
-        spConfigRun->WriteConfigValueInt("VersionClear", "LastCondi", nLstFailed);
-        spConfigRun->WriteConfigValue("VersionClear", "LastTime",
-            (LPCTSTR)CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
-
         if (nDelVersionCnt > 0) {
             std::string warn = "Delete Vesion file count : " + std::to_string((long long)nDelVersionCnt) + ".  ----- " + tInfo + ".";
             LogWarn(Severity_Low, Error_Debug, LOG_WARN_VER_DELETE, CSimpleStringA::Format("%s", warn.c_str()));
@@ -1090,7 +981,7 @@ void ResourceWatcherFSM::DeleteVideoFiles()
     }
 
     int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
-    nFileCount = ProcessFileDelete(videoPath.GetData(), nDelSuc, nDelFail, false, backDays);
+    nFileCount = ProcessFileDelete("RTA5A13", videoPath.GetData(), nDelSuc, nDelFail, false, backDays);
     DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete [Video] result(%s): count(%d), suc(%d), failed(%d).", videoPath.GetData(), nFileCount, nDelSuc, nDelFail);
 
 }

+ 1 - 1
Module/mod_ResourceWatcher/ResourceWatcherFSM.h

@@ -317,7 +317,7 @@ public:
 	void CenterSettingDelete();
 	BOOL DeleteVersionPackage();
 	void DeleteVideoFiles();
-	int ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt, bool delDir, unsigned int saveBackDay = 0);
+	int ProcessFileDelete(CSimpleStringA rtaCode, LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt, bool delDir, unsigned int saveBackDay = 0);
 
     BOOL DetectIsFirstRunAtBoot();