Ver código fonte

Z991239-5382 #comment feat: 清理逻辑中支持设置保留文件天数

陈纪林80310970 1 ano atrás
pai
commit
e6dabb3103

+ 3 - 3
DevAdapter/simulator/idcer.1.1/idcer.cmbsz.cpp

@@ -353,7 +353,7 @@ bool IDCerClassImpl::authHttpFunction()
     idCerReq.method = "readAndScan";
     idCerReq.adapterInterName = "IDCerAuthenticate";
 
-    string url = iniRead.ReadString("IDCertificate", "url", "");
+    string url = iniRead.ReadString("server", "url", "");
     if (url.length() == 0)
     {
         url = DEFAULT_URL;
@@ -400,7 +400,7 @@ bool IDCerClassImpl::exHttpFunction(IDCerInfoEx& idCerInfoEx)
     idCerReq.method = "readAndScan";
     idCerReq.adapterInterName = "IDCerGetDataEx";
 
-    string url = iniRead.ReadString("IDCertificate", "url", "");
+    string url = iniRead.ReadString("server", "url", "");
     if (url.length() == 0)
     {
         url = DEFAULT_URL;
@@ -487,7 +487,7 @@ bool IDCerClassImpl::ex2HttpFunction(IDCerInfoEx2& idCerInfoEx2)
     idCerReq.method = "readAndScanUTF8";
     idCerReq.adapterInterName = "IDCerGetDataEx2";
 
-    string url = iniRead.ReadString("IDCertificate", "url", "");
+    string url = iniRead.ReadString("server", "url", "");
     if (url.length() == 0)
     {
         url = DEFAULT_URL;

+ 33 - 5
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -653,10 +653,15 @@ void ResourceWatcherFSM::CenterSettingDelete()
 }
 
 //所有文件删除功能都用这个函数来处理 
-//bool delDir:控制是否将目录一并删除,false 保留目录, true 删除目录
-//int saveBackDay:保存多少天内的文件, 默认参数,默认值为0,即不保存
+//bool delDir:控制是否将目录一并删除,false 保留目录, true 删除目录
+//int saveBackDay:保存多少天内的文件, 默认参数,默认值为0,即不保存。(delDir = true时,该参数强制为0)
 int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt, bool delDir, unsigned int saveBackDay)
 {
+    if (delDir == true) //若要删除目录,则不保留任何文件
+    {
+        saveBackDay = 0;
+    }
+
     int fileCnt = 0;
     char* searchFilePath = new char[MAX_PATH];
     char* tempFilePath = new char[MAX_PATH];
@@ -675,8 +680,31 @@ int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int
     int fileLength = strlen(lpszPath);
     struct stat st;
 
-    if (stat(lpszPath, &st) < 0 || !S_ISDIR(st.st_mode)) {//单文件处理
-        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[%s] is not dir. Try to delete as single file.", lpszPath);
+    if (stat(lpszPath, &st) == -1)
+    {
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("[%s] Failed to get file stats.", lpszPath);
+        return fileCnt;
+    }
+
+    if (!S_ISDIR(st.st_mode)) 
+    {//单文件处理
+        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%s] is not dir. Try to delete as single file.", lpszPath);
+
+        if (saveBackDay != 0)
+        {
+            time_t lCreateTime, lSystemTime;
+            lCreateTime = st.st_ctime; //文件状态最后变化时间
+            time(&lSystemTime);
+
+            //文件存留天数
+            double delDays = (double)(lSystemTime - lCreateTime) / (double)SECONDS_OF_DAY;
+            if (delDays < saveBackDay) // 未达到需要清理的天数阈值,无需清理
+            {
+                Dbg("文件天数[%d], 删除阈值[%u],无需清理.", (int)delDays, saveBackDay);
+                return fileCnt;
+            }
+        }
+
         if (RemoveFileA(lpszPath)) {
             nDelSucCnt++;
             fileCnt++;
@@ -771,7 +799,7 @@ int ResourceWatcherFSM::ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int
                 double delDays = (double)(lSystemTime - lCreateTime) / (double)SECONDS_OF_DAY;
                 if (delDays < saveBackDay) // 未达到需要清理的天数阈值,无需清理
                 {
-                    Dbg("无需清理");
+                    Dbg("文件天数[%d], 删除阈值[%d],无需清理.", (int)delDays, saveBackDay);
                     return fileCnt;
                 }
             }