Skip to content

Commit b9e394b

Browse files
committed
added:rewrite file choice support
1 parent 59d3c98 commit b9e394b

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

XEngine_Source/StorageModule_Config/Config_Define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ typedef struct
119119
struct
120120
{
121121
bool bCreateDir;
122+
bool bRewrite;
122123
}st_PermissionFlags;
123124
}XENGINE_STORAGEBUCKET;
124125
typedef struct

XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ BOOL CConfig_Json::Config_Json_LoadBalance(LPCTSTR lpszConfigFile, XENGINE_LBCON
354354

355355
Json::Value st_JsonPermission = st_JsonBucket[i]["PermissionFlags"];
356356
st_Bucket.st_PermissionFlags.bCreateDir = st_JsonPermission["CreateDir"].asBool();
357+
st_Bucket.st_PermissionFlags.bRewrite = st_JsonPermission["Rewrite"].asBool();
358+
357359
pSt_ServerConfig->st_LoadBalance.pStl_ListBucket->push_back(st_Bucket);
358360
}
359361
return TRUE;

XEngine_Source/StorageModule_Session/Session_Define.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct
2424
__int64x ullRWLen; //已经读取(写入)的大小
2525
__int64x ullPosStart; //开始位置
2626
__int64x ullPosEnd; //结束位置
27+
BOOL bRewrite; //是否为覆写
2728

2829
int nLimit; //限制工具
2930
XHANDLE xhToken;
@@ -331,12 +332,17 @@ extern "C" BOOL Session_UPStroage_Destory();
331332
类型:整数型
332333
可空:N
333334
意思:输入文件大小
334-
参数.五:nPosStart
335+
参数.五:bRewrite
336+
In/Out:In
337+
类型:整数型
338+
可空:N
339+
意思:是否允许覆写
340+
参数.六:nPosStart
335341
In/Out:In
336342
类型:整数型
337343
可空:Y
338344
意思:输入起始位置
339-
参数.:nPostEnd
345+
参数.:nPostEnd
340346
In/Out:In
341347
类型:整数型
342348
可空:Y
@@ -346,7 +352,7 @@ extern "C" BOOL Session_UPStroage_Destory();
346352
意思:是否成功
347353
备注:
348354
*********************************************************************/
349-
extern "C" BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, int nPosStart = 0, int nPostEnd = 0);
355+
extern "C" BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, BOOL bRewrite, int nPosStart = 0, int nPostEnd = 0);
350356
/********************************************************************
351357
函数名称:Session_UPStroage_GetInfo
352358
函数功能:获取上传客户端信息

XEngine_Source/StorageModule_Session/Session_Error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
#define ERROR_STORAGE_MODULE_SESSION_NOTFOUND 0x0010004
2020
#define ERROR_STORAGE_MODULE_SESSION_PASSWORD 0x0010005
2121
#define ERROR_STORAGE_MODULE_SESSION_EMPTY 0x0010006
22-
#define ERROR_STORAGE_MODULE_SESSION_MAXCONNECT 0x0010007
22+
#define ERROR_STORAGE_MODULE_SESSION_MAXCONNECT 0x0010007
23+
#define ERROR_STORAGE_MODULE_SESSION_REWRITE 0x0010008

XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,17 @@ BOOL CSession_UPStroage::Session_UPStroage_Destory()
8787
类型:整数型
8888
可空:N
8989
意思:输入文件大小
90-
参数.五:nPosStart
90+
参数.五:bRewrite
91+
In/Out:In
92+
类型:整数型
93+
可空:N
94+
意思:是否允许覆写
95+
参数.六:nPosStart
9196
In/Out:In
9297
类型:整数型
9398
可空:Y
9499
意思:输入起始位置
95-
参数.:nPostEnd
100+
参数.:nPostEnd
96101
In/Out:In
97102
类型:整数型
98103
可空:Y
@@ -102,7 +107,7 @@ BOOL CSession_UPStroage::Session_UPStroage_Destory()
102107
意思:是否成功
103108
备注:
104109
*********************************************************************/
105-
BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, int nPosStart /* = 0 */, int nPostEnd /* = 0 */)
110+
BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, BOOL bRewrite, int nPosStart /* = 0 */, int nPostEnd /* = 0 */)
106111
{
107112
Session_IsErrorOccur = FALSE;
108113

@@ -140,7 +145,7 @@ BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTST
140145
memset(&st_FStat, '\0', sizeof(struct _tstat64));
141146
_tstat64(st_Client.st_StorageInfo.tszFileDir, &st_FStat);
142147
st_Client.st_StorageInfo.ullRWLen = st_FStat.st_size;
143-
148+
//追加打开
144149
st_Client.st_StorageInfo.pSt_File = _tfopen(lpszFileDir, _T("rb+"));
145150
if (NULL == st_Client.st_StorageInfo.pSt_File)
146151
{
@@ -151,7 +156,15 @@ BOOL CSession_UPStroage::Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTST
151156
//是不是覆写?
152157
if (st_Client.st_StorageInfo.ullRWLen > nPosStart)
153158
{
154-
//
159+
//是否允许覆写
160+
if (!bRewrite)
161+
{
162+
Session_IsErrorOccur = TRUE;
163+
Session_dwErrorCode = ERROR_STORAGE_MODULE_SESSION_REWRITE;
164+
fclose(st_Client.st_StorageInfo.pSt_File);
165+
return FALSE;
166+
}
167+
st_Client.st_StorageInfo.bRewrite = TRUE;
155168
st_Client.st_StorageInfo.ullRWLen -= (nPostEnd - nPosStart);
156169
}
157170
fseek(st_Client.st_StorageInfo.pSt_File, nPosStart, SEEK_SET);

XEngine_Source/StorageModule_Session/Session_Stroage/Session_UPStroage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CSession_UPStroage
2424
public:
2525
BOOL Session_UPStroage_Init(int nMaxConnect, BOOL bUPResume = FALSE);
2626
BOOL Session_UPStroage_Destory();
27-
BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, int nPosStart = 0, int nPostEnd = 0);
27+
BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, BOOL bRewrite, int nPosStart = 0, int nPostEnd = 0);
2828
BOOL Session_UPStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAGEINFO* pSt_StorageInfo);
2929
BOOL Session_UPStroage_Write(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen);
3030
BOOL Session_UPStroage_Exist(LPCTSTR lpszClientAddr);

XEngine_Source/StorageModule_Session/pch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ extern "C" BOOL Session_UPStroage_Destory()
9696
{
9797
return m_UPStorage.Session_UPStroage_Destory();
9898
}
99-
extern "C" BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, int nPosStart, int nPostEnd)
99+
extern "C" BOOL Session_UPStroage_Insert(LPCTSTR lpszClientAddr, LPCTSTR lpszBuckKey, LPCTSTR lpszFileDir, __int64x nFileSize, BOOL bRewrite, int nPosStart, int nPostEnd)
100100
{
101-
return m_UPStorage.Session_UPStroage_Insert(lpszClientAddr, lpszBuckKey, lpszFileDir, nFileSize, nPosStart, nPostEnd);
101+
return m_UPStorage.Session_UPStroage_Insert(lpszClientAddr, lpszBuckKey, lpszFileDir, nFileSize, bRewrite, nPosStart, nPostEnd);
102102
}
103103
extern "C" BOOL Session_UPStroage_GetInfo(LPCTSTR lpszClientAddr, SESSION_STORAGEINFO * pSt_StorageInfo)
104104
{

0 commit comments

Comments
 (0)