From e9ec57a661c9c2b48ff7ca4b0ce3d5ffbce61ffb Mon Sep 17 00:00:00 2001 From: Didier Wenzek Date: Tue, 22 Oct 2024 18:37:58 +0200 Subject: [PATCH] fixup! Improve struct WorkflowSource Simply use bool instead of WorkflowSource<()> which usage was not really clear. Signed-off-by: Didier Wenzek --- .../src/operation_workflows/persist.rs | 4 ++-- .../core/tedge_api/src/workflow/supervisor.rs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/crates/core/tedge_agent/src/operation_workflows/persist.rs b/crates/core/tedge_agent/src/operation_workflows/persist.rs index 09038fae99..01d13efbc9 100644 --- a/crates/core/tedge_agent/src/operation_workflows/persist.rs +++ b/crates/core/tedge_agent/src/operation_workflows/persist.rs @@ -246,10 +246,10 @@ impl WorkflowRepository { .find(|(_, (_, p))| p == removed_path) .map(|(n, (v, _))| (n.clone(), v.clone()))?; self.definitions.remove(&operation); - let deprecated = self + let builtin_restored = self .workflows .unregister_custom_workflow(&operation, &removed_version); - if matches!(deprecated, Some(WorkflowSource::BuiltIn)) { + if builtin_restored { info!("The builtin workflow for the '{operation}' operation has been restored"); None } else { diff --git a/crates/core/tedge_api/src/workflow/supervisor.rs b/crates/core/tedge_api/src/workflow/supervisor.rs index d4cf47493c..7f19536e93 100644 --- a/crates/core/tedge_api/src/workflow/supervisor.rs +++ b/crates/core/tedge_api/src/workflow/supervisor.rs @@ -45,31 +45,29 @@ impl WorkflowSupervisor { /// Un-register a user-defined workflow /// - /// Return None is this was the last version for that operation. - /// Return Some(BuiltIn) is there is a builtin definition - /// Return Some(InUseCopy) if the workflow has been deprecated but there is still a running command. + /// Return true if a builtin version has been restored pub fn unregister_custom_workflow( &mut self, operation: &OperationName, version: &WorkflowVersion, - ) -> Option> { + ) -> bool { let operation = OperationType::from(operation.as_str()); if let Some(versions) = self.workflows.get_mut(&operation) { versions.remove(version); } - let current_source = match self.workflows.get(&operation) { - None => None, - Some(version) if version.is_empty() => None, - Some(version) if version.is_builtin() => Some(BuiltIn), - Some(_) => Some(InUseCopy(())), + let (empty,builtin_restored) = match self.workflows.get(&operation) { + None => (true, false), + Some(version) if version.is_empty() => (true, false), + Some(version) if version.is_builtin() => (false, true), + Some(_) => (false, false), }; - if current_source.is_none() { + if empty { self.workflows.remove(&operation); } - current_source + builtin_restored } /// The set of pending commands