Removed the directory name of the message file name in the database column "nxsFile".

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7565 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-09-27 12:43:25 +00:00
parent afb883e012
commit 480e8e1385

View File

@ -390,6 +390,22 @@ RsNxsGrp* RsDataService::locked_getGroup(RetroCursor &c)
data_len = c.getInt32(COL_NXS_FILE_LEN); data_len = c.getInt32(COL_NXS_FILE_LEN);
offset = c.getInt32(COL_NXS_FILE_OFFSET); offset = c.getInt32(COL_NXS_FILE_OFFSET);
// first try to find the file in the service dir
if (RsDirUtil::fileExists(mServiceDir + "/" + grpFile)) {
grpFile.insert(0, mServiceDir + "/");
} else if (RsDirUtil::fileExists(grpFile)) {
// use old way for backward compatibility
//TODO: can be removed later
} else {
ok = false;
//#ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::locked_getGroup() cannot find group file " << grpFile;
std::cerr << std::endl;
//#endif
}
if (ok) {
char grp_data[data_len]; char grp_data[data_len];
std::ifstream istrm(grpFile.c_str(), std::ios::binary); std::ifstream istrm(grpFile.c_str(), std::ios::binary);
istrm.seekg(offset, std::ios::beg); istrm.seekg(offset, std::ios::beg);
@ -399,6 +415,7 @@ RsNxsGrp* RsDataService::locked_getGroup(RetroCursor &c)
offset = 0; offset = 0;
ok &= grp->grp.GetTlv(grp_data, data_len, &offset); ok &= grp->grp.GetTlv(grp_data, data_len, &offset);
} }
}
if(ok) if(ok)
return grp; return grp;
@ -502,6 +519,22 @@ RsNxsMsg* RsDataService::locked_getMessage(RetroCursor &c)
if(ok){ if(ok){
// first try to find the file in the service dir
if (RsDirUtil::fileExists(mServiceDir + "/" + msgFile)) {
msgFile.insert(0, mServiceDir + "/");
} else if (RsDirUtil::fileExists(msgFile)) {
// use old way for backward compatibility
//TODO: can be removed later
} else {
ok = false;
//#ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::locked_getMessage() cannot find message file " << msgFile;
std::cerr << std::endl;
//#endif
}
if (ok) {
char* msg_data = new char[data_len]; char* msg_data = new char[data_len];
std::ifstream istrm(msgFile.c_str(), std::ios::binary); std::ifstream istrm(msgFile.c_str(), std::ios::binary);
istrm.seekg(offset, std::ios::beg); istrm.seekg(offset, std::ios::beg);
@ -512,6 +545,7 @@ RsNxsMsg* RsDataService::locked_getMessage(RetroCursor &c)
ok &= msg->msg.GetTlv(msg_data, data_len, &offset); ok &= msg->msg.GetTlv(msg_data, data_len, &offset);
delete[] msg_data; delete[] msg_data;
} }
}
if(ok) if(ok)
return msg; return msg;
@ -552,7 +586,8 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
} }
// create or access file in binary // create or access file in binary
std::string msgFile = mServiceDir + "/" + msgPtr->grpId.toStdString() + "-msgs"; std::string filename = msgPtr->grpId.toStdString() + "-msgs";
std::string msgFile = mServiceDir + "/" + filename;
std::fstream ostrm(msgFile.c_str(), std::ios::binary | std::ios::app | std::ios::out); std::fstream ostrm(msgFile.c_str(), std::ios::binary | std::ios::app | std::ios::out);
ostrm.seekg(0, std::ios::end); // go to end to append ostrm.seekg(0, std::ios::end); // go to end to append
uint32_t offset = ostrm.tellg(); // get fill offset uint32_t offset = ostrm.tellg(); // get fill offset
@ -560,7 +595,7 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
ContentValue cv; ContentValue cv;
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset); cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
cv.put(KEY_NXS_FILE, msgFile); cv.put(KEY_NXS_FILE, filename);
cv.put(KEY_NXS_FILE_LEN, (int32_t)msgPtr->msg.TlvSize()); cv.put(KEY_NXS_FILE_LEN, (int32_t)msgPtr->msg.TlvSize());
cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId.toStdString()); cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId.toStdString());
cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId.toStdString()); cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId.toStdString());
@ -661,7 +696,8 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
std::string grpFile = mServiceDir + "/" + grpPtr->grpId.toStdString(); std::string filename = grpPtr->grpId.toStdString();
std::string grpFile = mServiceDir + "/" + filename;
std::fstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::app | std::ios::out); std::fstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::app | std::ios::out);
ostrm.seekg(0, std::ios::end); // go to end to append ostrm.seekg(0, std::ios::end); // go to end to append
uint32_t offset = ostrm.tellg(); // get fill offset uint32_t offset = ostrm.tellg(); // get fill offset
@ -675,7 +711,7 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
ContentValue cv; ContentValue cv;
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset); cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
cv.put(KEY_NXS_FILE_LEN, (int32_t)grpPtr->grp.TlvSize()); cv.put(KEY_NXS_FILE_LEN, (int32_t)grpPtr->grp.TlvSize());
cv.put(KEY_NXS_FILE, grpFile); cv.put(KEY_NXS_FILE, filename);
cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString()); cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString());
cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName); cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName);
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString()); cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString());
@ -759,7 +795,8 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
// if data is larger than max item size do not add // if data is larger than max item size do not add
if(!validSize(grpPtr)) continue; if(!validSize(grpPtr)) continue;
std::string grpFile = mServiceDir + "/" + grpPtr->grpId.toStdString(); std::string filename = grpPtr->grpId.toStdString();
std::string grpFile = mServiceDir + "/" + filename;
std::ofstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::trunc); std::ofstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::trunc);
uint32_t offset = 0; // get file offset uint32_t offset = 0; // get file offset
@ -772,7 +809,7 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
ContentValue cv; ContentValue cv;
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset); cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
cv.put(KEY_NXS_FILE_LEN, (int32_t)grpPtr->grp.TlvSize()); cv.put(KEY_NXS_FILE_LEN, (int32_t)grpPtr->grp.TlvSize());
cv.put(KEY_NXS_FILE, grpFile); cv.put(KEY_NXS_FILE, filename);
cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString()); cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString());
cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName); cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName);
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString()); cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString());