From 5a65a46bfe8671ea38710d0fbd230fe6a86ea508 Mon Sep 17 00:00:00 2001
From: renoseven <dev@renoseven.net>
Date: Fri, 18 Oct 2024 03:10:05 +0800
Subject: [PATCH] syscared: fix active accepted patch failure issue

Signed-off-by: renoseven <dev@renoseven.net>
---
 syscared/src/patch/manager.rs | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/syscared/src/patch/manager.rs b/syscared/src/patch/manager.rs
index 3a724db..a17703c 100644
--- a/syscared/src/patch/manager.rs
+++ b/syscared/src/patch/manager.rs
@@ -47,6 +47,7 @@ const PATCH_REMOVE: TransitionAction = &PatchManager::driver_remove_patch;
 const PATCH_ACTIVE: TransitionAction = &PatchManager::driver_active_patch;
 const PATCH_DEACTIVE: TransitionAction = &PatchManager::driver_deactive_patch;
 const PATCH_ACCEPT: TransitionAction = &PatchManager::driver_accept_patch;
+const PATCH_DECLINE: TransitionAction = &PatchManager::driver_decline_patch;
 
 lazy_static! {
     static ref STATUS_TRANSITION_MAP: IndexMap<Transition, Vec<TransitionAction>> = indexmap! {
@@ -59,9 +60,9 @@ lazy_static! {
         (PatchStatus::Actived, PatchStatus::NotApplied) => vec![PATCH_DEACTIVE, PATCH_REMOVE],
         (PatchStatus::Actived, PatchStatus::Deactived) => vec![PATCH_DEACTIVE],
         (PatchStatus::Actived, PatchStatus::Accepted) => vec![PATCH_ACCEPT],
-        (PatchStatus::Accepted, PatchStatus::NotApplied) => vec![PATCH_ACCEPT, PATCH_DEACTIVE, PATCH_REMOVE],
-        (PatchStatus::Accepted, PatchStatus::Deactived) => vec![PATCH_ACCEPT, PATCH_DEACTIVE],
-        (PatchStatus::Accepted, PatchStatus::Actived) => vec![PATCH_ACCEPT],
+        (PatchStatus::Accepted, PatchStatus::NotApplied) => vec![PATCH_DECLINE, PATCH_DEACTIVE, PATCH_REMOVE],
+        (PatchStatus::Accepted, PatchStatus::Deactived) => vec![PATCH_DECLINE, PATCH_DEACTIVE],
+        (PatchStatus::Accepted, PatchStatus::Actived) => vec![PATCH_DECLINE],
     };
 }
 
@@ -471,6 +472,10 @@ impl PatchManager {
     fn driver_accept_patch(&mut self, patch: &Patch, _flag: PatchOpFlag) -> Result<()> {
         self.set_patch_status(patch, PatchStatus::Accepted)
     }
+
+    fn driver_decline_patch(&mut self, patch: &Patch, _flag: PatchOpFlag) -> Result<()> {
+        self.set_patch_status(patch, PatchStatus::Actived)
+    }
 }
 
 impl Drop for PatchManager {
-- 
2.34.1

