Эх сурвалжийг харах

Z991239-3037 #comment [mod_upload] 上传去分行化改造(修复视频文件删除后移动操作失败问题)

Signed-Off-By: commit-hook
刘文涛80174520 3 жил өмнө
parent
commit
d1634d7d29

+ 85 - 5
Module/mod_upload/UploadFSM.cpp

@@ -386,8 +386,11 @@ namespace Task
 			//rootReq["first_sm3"] = firstMD5Str.c_str();
 			//rootReq["last_sm3"] = lastMD5Str.c_str();
 			rootReq["file_head_custom"] = m_fsm->m_currUploadFile->decHeadJson.c_str();//自定义解密的头json格式,可为空
+#ifdef RVC_OS_WIN
 			rootReq["system_type"] = "W";//系统标记,代表路径分隔符
-
+#else
+			rootReq["system_type"] = "L";//系统标记,代表路径分隔符
+#endif
 			string jsonReq = writer.write(rootReq);
 
 			qTempReq.url = httpUrl;
@@ -615,6 +618,7 @@ namespace Task
 			if(m_fsm->m_currUploadFile->after_deal_type=="D"){
 
 				Dbg("delete file %s",m_fsm->m_currUploadFile->fileName.c_str());
+#ifdef RVC_OS_WIN
 				if(remove(m_fsm->m_currUploadFile->filePath.c_str())==0){
 					Dbg("delete file is ok");
 					return true;
@@ -623,7 +627,24 @@ namespace Task
 					errmsg = CSimpleStringA::Format("delete file is error, errno=%d",GetLastError());
 					return false;
 				}
-
+#else
+				if (changeFileAtt(m_fsm->m_currUploadFile->filePath.c_str()) == 0) {
+					if (remove(m_fsm->m_currUploadFile->filePath.c_str()) == 0) {
+						Dbg("delete file is ok");
+						return true;
+					}
+					else {
+						Dbg("delete file is error, errno=%d", errno);
+						errmsg = CSimpleStringA::Format("delete file is error, errno=%d", errno);
+						return false;
+					}
+				}
+				else {
+					Dbg("delete file is error,changefileAtt fail, errno=%d", errno);
+					errmsg = CSimpleStringA::Format("delete file is error,changefileAtt fail, errno=%d", errno);
+					return false;
+				}
+#endif
 			}else if(m_fsm->m_currUploadFile->after_deal_type=="M"){
 				string destPath="";
 				string destDir="";
@@ -647,6 +668,7 @@ namespace Task
 				string srcPath = m_fsm->m_currUploadFile->filePath;
 				Dbg("move file %s to %s",srcPath.c_str(),destPath.c_str());
 				//判断是否存在目标文件,如存在,则先删除
+#ifdef RVC_OS_WIN
 				if(ExistsFileA(destPath.c_str())){
 					if(remove(destPath.c_str())==0){
 						Dbg("delete dest file is ok");
@@ -680,7 +702,66 @@ namespace Task
 					}
 				}
 				return isSucc;
-				
+#else
+				if (ExistsFileA(destPath.c_str())) {
+					if (changeFileAtt(destPath.c_str()) == 0) {
+						if (remove(destPath.c_str()) == 0) {
+							Dbg("delete dest file is ok");
+						}
+						else {
+							Dbg("delete dest file is error, errno=%d", errno);
+							errmsg = CSimpleStringA::Format("delete src file is error, errno=%d", errno);
+							return false;
+						}
+					}
+					else {
+						Dbg("delete dest file is error,changefileAtt fail ,errno=%d , file=%s ", errno, destPath.c_str());
+						errmsg = CSimpleStringA::Format("delete src file is error, changefileAtt fail, errno=%d", errno);
+						return false;
+					}
+				}
+				//判断移动目标文件夹是否存在,不存在,则创建
+				if (!ExistsDirA(destDir.c_str())) {
+					if (!CreateDirRecursiveA(destDir.c_str())) {
+						Dbg("create dest dir [%s] is error, errno=%d", destDir.c_str(), errno);
+						errmsg = CSimpleStringA::Format("create dest dir [%s] is error, errno=%d", destDir.c_str(), errno);
+						return false;
+					}
+				}
+				//移动文件
+				if (changeFileAtt(srcPath.c_str()) == 0)
+				{
+					int i;
+					int tries = 10;
+					bool isSucc = false;
+					for (i = 0; i < tries; ++i) {
+						//rename函数对于跨分支的目录存在拷贝不成功的情况,故采用先拷贝后删除的操作修复此bug
+						if (fileutil_copy_file(destPath.c_str(), srcPath.c_str()) == 0) {
+							if (remove(srcPath.c_str()) == 0) {
+								Dbg("move ok! tries:%d", i);
+								isSucc = true;
+								break;
+							}
+							else {
+								Dbg("move %s -> %s failed! delete src file fail, errno:%d", srcPath.c_str(), destPath.c_str(), errno);
+								errmsg = CSimpleStringA::Format("move failed! delete src file fail, srcPath=[%s], errno:%d", srcPath.c_str(), errno);
+								Sleep(1000);
+							}
+						}
+						else {
+							Dbg("move %s -> %s failed! copy src file fail, errno:%d", srcPath.c_str(), destPath.c_str(), errno);
+							errmsg = CSimpleStringA::Format("move failed! copy src file fail, destPath=[%s], errno:%d", destPath.c_str(), errno);
+							Sleep(1000);
+						}
+					}
+					return isSucc;
+				}
+				else {
+					Dbg("move %s -> %s failed! , changefileAtt fail,errno=%d", srcPath.c_str(), destPath.c_str(), errno);
+					errmsg = CSimpleStringA::Format("move failed! changefileAtt fail, srcPath=[%s], errno:%d", srcPath.c_str(), errno);
+					return false;
+				}
+#endif		
 			}else if(m_fsm->m_currUploadFile->after_deal_type=="N"){
 				return true;
 			}else{
@@ -1865,7 +1946,6 @@ void UploadFSM::post_process()
 			int i;
 			int tries = 10;
 			for (i = 0; i < tries; ++i) {
-
 				if (rename(m_uploading_file->path, to_path) == 0) {
 					Dbg("move ok! tries:%d", i);
 					break;
@@ -2050,7 +2130,7 @@ void UploadFSM::scanFile()
 			path = m_rootPath + "\\" + up->path_name;
 #else
 			path = m_rootPath + SPLIT_SLASH_STR + up->path_name;
-			//path = "/opt/" + up->path_name;
+			//path = "/opt/" + up->path_name;//test 
 #endif
 		}else if(up->path_type=="A"){
 			path=up->path_name;