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

Commit 32253d92 authored by Yifan Hong's avatar Yifan Hong
Browse files

libsnapshot: handle errors in RemoveAllUpdateState appropriately.

In CheckMergeState / HandleCancelledUpdate, if removing update state
fails, just return the previous state. It used to return Cancelled,
and the error goes unnoticed.

Test: pass
Bug: 147696014
Change-Id: I9cb3d20c5c886afa1913740c903eaad08f0cc041
parent 44b93df3
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -829,7 +829,9 @@ UpdateState SnapshotManager::CheckMergeState(const std::function<bool()>& before
        // lock, because flock() might have failed.
        // lock, because flock() might have failed.
        AcknowledgeMergeSuccess(lock.get());
        AcknowledgeMergeSuccess(lock.get());
    } else if (state == UpdateState::Cancelled) {
    } else if (state == UpdateState::Cancelled) {
        RemoveAllUpdateState(lock.get(), before_cancel);
        if (!RemoveAllUpdateState(lock.get(), before_cancel)) {
            return ReadSnapshotUpdateStatus(lock.get()).state();
        }
    }
    }
    return state;
    return state;
}
}
@@ -1186,8 +1188,7 @@ bool SnapshotManager::HandleCancelledUpdate(LockedFile* lock,
    // If all snapshots were reflashed, then cancel the entire update.
    // If all snapshots were reflashed, then cancel the entire update.
    if (AreAllSnapshotsCancelled(lock)) {
    if (AreAllSnapshotsCancelled(lock)) {
        LOG(WARNING) << "Detected re-flashing, cancelling unverified update.";
        LOG(WARNING) << "Detected re-flashing, cancelling unverified update.";
        RemoveAllUpdateState(lock, before_cancel);
        return RemoveAllUpdateState(lock, before_cancel);
        return true;
    }
    }


    // If update has been rolled back, then cancel the entire update.
    // If update has been rolled back, then cancel the entire update.
@@ -1209,8 +1210,7 @@ bool SnapshotManager::HandleCancelledUpdate(LockedFile* lock,
    }
    }


    LOG(WARNING) << "Detected rollback, cancelling unverified update.";
    LOG(WARNING) << "Detected rollback, cancelling unverified update.";
    RemoveAllUpdateState(lock, before_cancel);
    return RemoveAllUpdateState(lock, before_cancel);
    return true;
}
}


std::unique_ptr<LpMetadata> SnapshotManager::ReadCurrentMetadata() {
std::unique_ptr<LpMetadata> SnapshotManager::ReadCurrentMetadata() {