From 229b9961e4ccd91da771cf439fe5a957b85a72d5 Mon Sep 17 00:00:00 2001 From: Xinye Tao Date: Fri, 24 Jun 2022 15:07:30 +0800 Subject: [PATCH] simplify `delete_metadata` trait method (#232) (#233) Signed-off-by: tabokie --- src/engine.rs | 6 ++++-- src/env/mod.rs | 4 ++-- src/file_pipe_log/pipe_builder.rs | 11 ++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 14f6bdfd..cb47937a 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1637,8 +1637,10 @@ mod tests { Ok(()) } - fn delete_metadata>(&self, path: P) -> std::io::Result { - Ok(self.inner.delete_metadata(&path)? | self.update_metadata(path.as_ref(), true)) + fn delete_metadata>(&self, path: P) -> std::io::Result<()> { + self.inner.delete_metadata(&path)?; + self.update_metadata(path.as_ref(), true); + Ok(()) } fn exists_metadata>(&self, path: P) -> bool { diff --git a/src/env/mod.rs b/src/env/mod.rs index 388b6de4..3f7628c4 100644 --- a/src/env/mod.rs +++ b/src/env/mod.rs @@ -29,8 +29,8 @@ pub trait FileSystem: Send + Sync { /// going through user implemented cleanup procedure. This method is used to /// detect and cleanup the user metadata that is no longer mapped to a /// physical file. - fn delete_metadata>(&self, _path: P) -> Result { - Ok(false) + fn delete_metadata>(&self, _path: P) -> Result<()> { + Ok(()) } /// Returns whether there is any user metadata associated with given `path`. diff --git a/src/file_pipe_log/pipe_builder.rs b/src/file_pipe_log/pipe_builder.rs index bec4f3fa..9dd46280 100644 --- a/src/file_pipe_log/pipe_builder.rs +++ b/src/file_pipe_log/pipe_builder.rs @@ -164,14 +164,11 @@ impl DualPipesBuilder { for seq in start..min_id { let file_id = FileId { queue, seq }; let path = file_id.build_file_path(dir); - match self.file_system.delete_metadata(&path) { - Err(e) => { - error!("failed to delete metadata of {}: {}.", path.display(), e); - break; - } - Ok(true) => success += 1, - _ => {} + if let Err(e) = self.file_system.delete_metadata(&path) { + error!("failed to delete metadata of {}: {}.", path.display(), e); + break; } + success += 1; } warn!( "deleted {} stale files of {:?} in range [{}, {}).",