Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 692cdf94 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "libsnapshot: fix stats write in Resume()" am: 20d9d6a6 am: b568c330

Change-Id: Ica782d25b00bd75e411a7c38e210dac88397bab3
parents 29651ce5 b568c330
Loading
Loading
Loading
Loading
+25 −16
Original line number Diff line number Diff line
@@ -36,36 +36,45 @@ SnapshotMergeStats::~SnapshotMergeStats() {
    }
}

void SnapshotMergeStats::Start() {
    SnapshotMergeReport report;
    report.set_resume_count(0);
    report.set_state(UpdateState::None);
bool SnapshotMergeStats::ReadState() {
    std::string contents;
    if (!android::base::ReadFileToString(parent_.GetMergeStateFilePath(), &contents)) {
        PLOG(INFO) << "Read merge statistics file failed";
        return false;
    }
    if (!report_.ParseFromString(contents)) {
        LOG(ERROR) << "Unable to parse merge statistics file as SnapshotMergeReport";
        return false;
    }
    return true;
}

bool SnapshotMergeStats::WriteState() {
    std::string contents;
    if (!report.SerializeToString(&contents)) {
    if (!report_.SerializeToString(&contents)) {
        LOG(ERROR) << "Unable to serialize SnapshotMergeStats.";
        return;
        return false;
    }
    auto file_path = parent_.GetMergeStateFilePath();
    if (!WriteStringToFileAtomic(contents, file_path)) {
        PLOG(ERROR) << "Could not write to merge statistics file";
        return;
        return false;
    }
    return true;
}

void SnapshotMergeStats::Resume() {
    std::string contents;
    if (!android::base::ReadFileToString(parent_.GetMergeStateFilePath(), &contents)) {
        PLOG(INFO) << "Read merge statistics file failed";
        return;
void SnapshotMergeStats::Start() {
    report_.set_resume_count(0);
    report_.set_state(UpdateState::None);
    WriteState();
}

    if (!report_.ParseFromString(contents)) {
        LOG(ERROR) << "Unable to parse merge statistics file as SnapshotMergeReport";
void SnapshotMergeStats::Resume() {
    if (!ReadState()) {
        return;
    }

    report_.set_resume_count(report_.resume_count() + 1);
    WriteState();
}

void SnapshotMergeStats::set_state(android::snapshot::UpdateState state) {
+3 −0
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ class SnapshotMergeStats {
    SnapshotMergeReport GetReport();

  private:
    bool ReadState();
    bool WriteState();

    const SnapshotManager& parent_;
    SnapshotMergeReport report_;
    std::chrono::time_point<std::chrono::steady_clock> init_time_;