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

Commit 0b32b199 authored by Yifan Hong's avatar Yifan Hong
Browse files

libsnapshot: operator<< for UpdateState

Test: pass
Change-Id: Ifc88666d0b7c76f3ea9b7ec662398084d631c4e6
parent 7509fca9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <chrono>
#include <map>
#include <memory>
#include <ostream>
#include <string>
#include <string_view>
#include <vector>
@@ -84,6 +85,7 @@ enum class UpdateState : unsigned int {
    // operation via fastboot. This state can only be returned by WaitForMerge.
    Cancelled
};
std::ostream& operator<<(std::ostream& os, UpdateState state);

class SnapshotManager final {
    using CreateLogicalPartitionParams = android::fs_mgr::CreateLogicalPartitionParams;
+16 −17
Original line number Diff line number Diff line
@@ -1526,34 +1526,33 @@ UpdateState SnapshotManager::ReadUpdateState(LockedFile* file) {
    }
}

bool SnapshotManager::WriteUpdateState(LockedFile* file, UpdateState state) {
    std::string contents;
std::ostream& operator<<(std::ostream& os, UpdateState state) {
    switch (state) {
        case UpdateState::None:
            contents = "none";
            break;
            return os << "none";
        case UpdateState::Initiated:
            contents = "initiated";
            break;
            return os << "initiated";
        case UpdateState::Unverified:
            contents = "unverified";
            break;
            return os << "unverified";
        case UpdateState::Merging:
            contents = "merging";
            break;
            return os << "merging";
        case UpdateState::MergeCompleted:
            contents = "merge-completed";
            break;
            return os << "merge-completed";
        case UpdateState::MergeNeedsReboot:
            contents = "merge-needs-reboot";
            break;
            return os << "merge-needs-reboot";
        case UpdateState::MergeFailed:
            contents = "merge-failed";
            break;
            return os << "merge-failed";
        default:
            LOG(ERROR) << "Unknown update state";
            return false;
            return os;
    }
}

bool SnapshotManager::WriteUpdateState(LockedFile* file, UpdateState state) {
    std::stringstream ss;
    ss << state;
    std::string contents = ss.str();
    if (contents.empty()) return false;

    if (!Truncate(file)) return false;
    if (!android::base::WriteStringToFd(contents, file->fd())) {