mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
Rename ap file when save
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I7H5R2 Signed-off-by: hzzhouzebin <zhouzebin1@huawei.com> Change-Id: I9c7e3a69fb9817481fd9a2168e354184a067babb
This commit is contained in:
parent
a54b399699
commit
371690dfc1
@ -13,6 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
|
||||
#include "ecmascript/pgo_profiler/pgo_profiler_encoder.h"
|
||||
|
||||
#include "ecmascript/platform/file.h"
|
||||
@ -79,15 +82,21 @@ bool PGOProfilerEncoder::Save()
|
||||
|
||||
bool PGOProfilerEncoder::SaveProfiler(const SaveTask *task)
|
||||
{
|
||||
std::ofstream fileStream(realOutPath_.c_str());
|
||||
static const char *tempSuffix = ".tmp";
|
||||
auto tmpOutPath = realOutPath_ + tempSuffix;
|
||||
std::ofstream fileStream(tmpOutPath.c_str());
|
||||
if (!fileStream.is_open()) {
|
||||
LOG_ECMA(ERROR) << "The file path(" << realOutPath_ << ") open failure!";
|
||||
LOG_ECMA(ERROR) << "The file path(" << tmpOutPath << ") open failure!";
|
||||
return false;
|
||||
}
|
||||
pandaFileInfos_->ProcessToBinary(fileStream, header_->GetPandaInfoSection());
|
||||
globalRecordInfos_->ProcessToBinary(task, fileStream, header_);
|
||||
header_->ProcessToBinary(fileStream);
|
||||
fileStream.close();
|
||||
if (rename(tmpOutPath.c_str(), realOutPath_.c_str())) {
|
||||
LOG_ECMA(ERROR) << "Rename " << tmpOutPath << " --> " << realOutPath_ << " failure!, errno: " << errno;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user