瀏覽代碼

Z991239-5647 #comment 解决上传到服务端交易录像存在加密前缀问题

80274480 1 年之前
父節點
當前提交
40264b6948
共有 2 個文件被更改,包括 36 次插入9 次删除
  1. 2 1
      Module/mod_recorder/Event.h
  2. 34 8
      Module/mod_recorder/mod_recorder.cpp

+ 2 - 1
Module/mod_recorder/Event.h

@@ -14,4 +14,5 @@
 #define LOG_EVT_RECORDING_FAILED					0x31210006				//交易录像录制失败
 #define LOG_EVT_RECORD_ENTITY_EXCEPTION				0x31210007				//录像实体异常
 #define LOG_EVT_POST_RECORDINFO_FAILED				0x31210008				//上报录像信息失败
-#define LOG_EVT_POST_RECORDINFO_COST_TIME			0x31210009				//上报录像信息耗时
+#define LOG_EVT_POST_RECORDINFO_COST_TIME			0x31210009				//上报录像信息耗时
+#define LOG_EVT_ABNORMAL_RECORD_FILE				0x3121000A				//异常录像文件

+ 34 - 8
Module/mod_recorder/mod_recorder.cpp

@@ -969,15 +969,15 @@ int CRecorderEntity::GetRecordVideoInfo(const char* videofilename, char* strSess
 int CRecorderEntity::SaveExceptionRecordVideos()
 {
 	int iRet = -1;
+
 #ifdef RVC_OS_WIN
-	char srcFilePath[MAX_PATH]={0};
 	WIN32_FIND_DATA FindFileData;
 	HANDLE hFind;
 	bool fFinished = false;
 	char strVideoFormat[MAX_PATH] = { 0 };
-	snprintf(strVideoFormat, MAX_PATH, "%s", RECORD_MP4_SUFFIX);
-
-	snprintf(srcFilePath, MAX_PATH, "%s*.%s", m_TempDir.GetData(), strVideoFormat);
+	char srcFilePath[MAX_PATH] = { 0 };
+	_snprintf(strVideoFormat, MAX_PATH, "%s", RECORD_MP4_SUFFIX);
+	_snprintf(srcFilePath, MAX_PATH, "%s*.%s", m_TempDir.GetData(), strVideoFormat);
 
 	hFind = FindFirstFile(srcFilePath, &FindFileData);
 
@@ -1002,6 +1002,11 @@ int CRecorderEntity::SaveExceptionRecordVideos()
 					filecryption_callback_t cb = {0};
 					cb.dbg = &rvcDbg;
 					if (false == is_file_encrypted(srcfile.GetData(), &cb)){
+						if (strstr(FindFileData.cFileName, RVC_FILEENC_STR)) {
+							RvcDeleteFile(srcfile.GetData());
+							goto on_next;
+						}
+
 						if (is_file_completed(srcfile.GetData(), &cb)) {
 							HandleEncryptVideoRecord(srcfile.GetData());
 						}
@@ -1010,20 +1015,28 @@ int CRecorderEntity::SaveExceptionRecordVideos()
 						char* pIndex = NULL;
 						if (pIndex = strstr(FindFileData.cFileName, RVC_FILEENC_STR)){
 							char strname[MAX_PATH] = {0};
-							memcpy(strname, pIndex+strlen(RVC_FILEENC_STR), strlen(pIndex+strlen(RVC_FILEENC_STR)));
-							CSimpleStringA tempsrcfile = CSimpleStringA::Format("%s%s",m_TempDir.GetData(), strname);
-							if (!rename(srcfile.GetData(),tempsrcfile.GetData())){
+							memcpy(strname, pIndex + strlen(RVC_FILEENC_STR), strlen(pIndex+strlen(RVC_FILEENC_STR)));
+							CSimpleStringA tempsrcfile = CSimpleStringA::Format("%s%s", m_TempDir.GetData(), strname);
+							if (rvcMoveFile(srcfile.GetData(),tempsrcfile.GetData())){
 								srcfile = tempsrcfile;
 								memset(FindFileData.cFileName, 0, MAX_PATH);
 								memcpy(FindFileData.cFileName, strname, strlen(strname));
 							}
 							else{
-								LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("Error Code %lu while rename %s.", GetLastError(), srcfile.GetData()).GetData());
+								LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("Error Code %lu while rename %s, delete it.", GetLastError(), srcfile.GetData()).GetData());
+								RvcDeleteFile(srcfile.GetData());
+								goto on_next;
 							}
 						}
 					}
 				}
 
+				if (strstr(srcfile.GetData(), RVC_FILEENC_STR)) {
+					LogWarn(Severity_Low, Error_Debug, LOG_EVT_ABNORMAL_RECORD_FILE, CSimpleStringA::Format("abnormal file %s, delete it.",  srcfile.GetData()).GetData());
+					RvcDeleteFile(srcfile.GetData());
+					goto on_next;
+				}
+
 				CSimpleStringA dstfile = CSimpleStringA::Format("%s%s",m_RecordSaveDir.GetData(), FindFileData.cFileName);
 				bool bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
 				if(!bRet) {
@@ -1070,6 +1083,11 @@ on_next:
 				filecryption_callback_t cb = { 0 };
 				cb.dbg = &rvcDbg;
 				if (false == is_file_encrypted(srcfile.GetData(), &cb)) {
+					if (strstr(ptr->d_name, RVC_FILEENC_STR)) {
+						RvcDeleteFile(srcfile.GetData());
+						continue;
+					}
+
 					if (is_file_completed(srcfile.GetData(), &cb)) {
 						HandleEncryptVideoRecord(srcfile.GetData());
 					}
@@ -1087,11 +1105,19 @@ on_next:
 						}
 						else {
 							LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORDER_RENAME_FAILED, CSimpleStringA::Format("%s(%d) while rename %s.", strerror(errno), errno, srcfile.GetData()).GetData());
+							RvcDeleteFile(srcfile.GetData());
+							continue;
 						}
 					}
 				}
 			}
 
+			if (strstr(srcfile.GetData(), RVC_FILEENC_STR)) {
+				LogWarn(Severity_Low, Error_Debug, LOG_EVT_ABNORMAL_RECORD_FILE, CSimpleStringA::Format("abnormal file %s, delete it.", srcfile.GetData()).GetData());
+				RvcDeleteFile(srcfile.GetData());
+				continue;
+			}
+
 			CSimpleStringA dstfile = CSimpleStringA::Format("%s%s", m_RecordSaveDir.GetData(), ptr->d_name);
 			bool bRet = rvcMoveFile(srcfile.GetData(), dstfile.GetData());
 			if (!bRet) {