!1193 fix snapshot serialize file not verified

Merge pull request !1193 from zhaozhibo/master
This commit is contained in:
openharmony_ci 2022-04-30 13:32:53 +00:00 committed by Gitee
commit 969bc4b456
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 14 additions and 17 deletions

View File

@ -38,8 +38,14 @@ constexpr uint32_t PANDA_FILE_ALIGNMENT = 4096;
void SnapShot::Serialize(TaggedObject *objectHeader, const panda_file::File *pf, const CString &fileName)
{
std::pair<bool, CString> filePath = VerifyFilePath(fileName);
if (!filePath.first) {
LOG(ERROR, RUNTIME) << "snapshot file path error";
return;
}
std::fstream write(fileName.c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
if (!VerifySnapShotFile(write, fileName)) {
if (!write.good()) {
LOG(DEBUG, RUNTIME) << "snapshot open file failed";
return;
}
@ -74,8 +80,14 @@ void SnapShot::Serialize(TaggedObject *objectHeader, const panda_file::File *pf,
void SnapShot::Serialize(uintptr_t startAddr, size_t size, const CString &fileName)
{
std::pair<bool, CString> filePath = VerifyFilePath(fileName);
if (!filePath.first) {
LOG(ERROR, RUNTIME) << "snapshot file path error";
return;
}
std::fstream write(fileName.c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
if (!VerifySnapShotFile(write, fileName)) {
if (!write.good()) {
LOG(DEBUG, RUNTIME) << "snapshot open file failed";
return;
}
@ -227,20 +239,6 @@ std::pair<bool, CString> SnapShot::VerifyFilePath(const CString &filePath)
return std::make_pair(false, "");
}
bool SnapShot::VerifySnapShotFile(std::fstream &write, const CString &fileName)
{
std::pair<bool, CString> filePath = VerifyFilePath(fileName);
if (!filePath.first) {
LOG(ERROR, RUNTIME) << "snapshot file path error";
return false;
}
if (!write.good()) {
LOG(DEBUG, RUNTIME) << "snapshot open file failed";
return false;
}
return true;
}
void SnapShot::WriteToFile(std::fstream &write, const panda_file::File *pf,
size_t size, const CVector<uintptr_t> &stringVector)
{

View File

@ -50,7 +50,6 @@ private:
private:
size_t AlignUpPageSize(size_t spaceSize);
std::pair<bool, CString> VerifyFilePath(const CString &filePath);
bool VerifySnapShotFile(std::fstream &write, const CString &fileName);
void WriteToFile(std::fstream &write, const panda_file::File *pf, size_t size,
const CVector<uintptr_t> &stringVector);