From 5f5402a3abd9fc2bbedf1e3af980eb050a035c3a Mon Sep 17 00:00:00 2001 From: tamo Date: Thu, 6 May 2021 18:12:57 +0200 Subject: [PATCH] provide a way to access the internal content path of all processing State --- .../src/index_controller/updates.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/meilisearch-http/src/index_controller/updates.rs b/meilisearch-http/src/index_controller/updates.rs index a129a25a0..6b5ef345d 100644 --- a/meilisearch-http/src/index_controller/updates.rs +++ b/meilisearch-http/src/index_controller/updates.rs @@ -72,6 +72,10 @@ impl Enqueued { pub fn content_path(&self) -> Option<&Path> { self.content.as_deref() } + + pub fn content_path_mut(&mut self) -> Option<&mut PathBuf> { + self.content.as_mut() + } } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -87,6 +91,14 @@ impl Processed { pub fn id(&self) -> u64 { self.from.id() } + + pub fn content_path(&self) -> Option<&Path> { + self.from.content_path() + } + + pub fn content_path_mut(&mut self) -> Option<&mut PathBuf> { + self.from.content_path_mut() + } } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -106,6 +118,14 @@ impl Processing { self.from.meta() } + pub fn content_path(&self) -> Option<&Path> { + self.from.content_path() + } + + pub fn content_path_mut(&mut self) -> Option<&mut PathBuf> { + self.from.content_path_mut() + } + pub fn process(self, success: UpdateResult) -> Processed { Processed { success, @@ -135,6 +155,14 @@ impl Aborted { pub fn id(&self) -> u64 { self.from.id() } + + pub fn content_path(&self) -> Option<&Path> { + self.from.content_path() + } + + pub fn content_path_mut(&mut self) -> Option<&mut PathBuf> { + self.from.content_path_mut() + } } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -150,6 +178,14 @@ impl Failed { pub fn id(&self) -> u64 { self.from.id() } + + pub fn content_path(&self) -> Option<&Path> { + self.from.content_path() + } + + pub fn content_path_mut(&mut self) -> Option<&mut PathBuf> { + self.from.content_path_mut() + } } #[derive(Debug, Serialize, Deserialize)] @@ -179,6 +215,26 @@ impl UpdateStatus { _ => None, } } + + pub fn content_path(&self) -> Option<&Path> { + match self { + UpdateStatus::Processing(u) => u.content_path(), + UpdateStatus::Processed(u) => u.content_path(), + UpdateStatus::Aborted(u) => u.content_path(), + UpdateStatus::Failed(u) => u.content_path(), + UpdateStatus::Enqueued(u) => u.content_path(), + } + } + + pub fn content_path_mut(&mut self) -> Option<&mut PathBuf> { + match self { + UpdateStatus::Processing(u) => u.content_path_mut(), + UpdateStatus::Processed(u) => u.content_path_mut(), + UpdateStatus::Aborted(u) => u.content_path_mut(), + UpdateStatus::Failed(u) => u.content_path_mut(), + UpdateStatus::Enqueued(u) => u.content_path_mut(), + } + } } impl From for UpdateStatus {