diff options
Diffstat (limited to 'plugins/plugin_fdman')
-rw-r--r-- | plugins/plugin_fdman/src/plugin.rs | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/plugins/plugin_fdman/src/plugin.rs b/plugins/plugin_fdman/src/plugin.rs index 2d2fa008..16fe362c 100644 --- a/plugins/plugin_fdman/src/plugin.rs +++ b/plugins/plugin_fdman/src/plugin.rs @@ -62,18 +62,16 @@ impl Handle<OpenOptions> for FdManPlugin { message: OpenOptions, sender: tedge_api::address::ReplySenderFor<OpenOptions>, ) -> Result<(), PluginError> { - async fn inner(guard: Guard, message: OpenOptions) -> OpenOptionsResult { - let file_result = message - .as_std() - .open(message.path()) - .map(|file| crate::file::FileGuard::new(file, guard)) - .map_err(Error::from) - .map_err(OpenOptionsError::from); - OpenOptionsResult::new(message, file_result) - } - HandleWithGuard::new(self, message, sender) - .with_handles(1, inner) + .with_handles(1, move |guard: Guard, message: OpenOptions| async { + let file_result = message + .as_std() + .open(message.path()) + .map(|file| crate::file::FileGuard::new(file, guard)) + .map_err(Error::from) + .map_err(OpenOptionsError::from); + OpenOptionsResult::new(message, file_result) + }) .await } } @@ -85,17 +83,15 @@ impl Handle<Copy> for FdManPlugin { message: Copy, sender: tedge_api::address::ReplySenderFor<Copy>, ) -> Result<(), PluginError> { - async fn inner(guard: Guard, message: Copy) -> CopyResult { - let copy_res = tokio::fs::copy(message.src(), message.dst()) - .await - .map_err(Error::from) - .map_err(CopyError::from); - drop(guard); // We can now drop the guard, as the copy process is done - CopyResult::new(message, copy_res) - } - HandleWithGuard::new(self, message, sender) - .with_handles(2, inner) + .with_handles(2, move |guard: Guard, message: Copy| async { + let copy_res = tokio::fs::copy(message.src(), message.dst()) + .await + .map_err(Error::from) + .map_err(CopyError::from); + drop(guard); // We can now drop the guard, as the copy process is done + CopyResult::new(message, copy_res) + }) .await } } @@ -107,17 +103,15 @@ impl Handle<Rename> for FdManPlugin { message: Rename, sender: tedge_api::address::ReplySenderFor<Rename>, ) -> Result<(), PluginError> { - async fn inner(guard: Guard, message: Rename) -> RenameResult { - let rename_res = tokio::fs::rename(message.src(), message.dst()) - .await - .map_err(Error::from) - .map_err(RenameError::from); - drop(guard); // We can now drop the guard, as the copy process is done - RenameResult::new(message, rename_res) - } - HandleWithGuard::new(self, message, sender) - .with_handles(2, inner) + .with_handles(2, move |guard: Guard, message: Rename| async { + let rename_res = tokio::fs::rename(message.src(), message.dst()) + .await + .map_err(Error::from) + .map_err(RenameError::from); + drop(guard); // We can now drop the guard, as the copy process is done + RenameResult::new(message, rename_res) + }) .await } } @@ -159,7 +153,7 @@ where async fn with_handles<F, Fut>(self, handles_to_aquire: u64, fun: F) -> Result<(), PluginError> where - F: Fn(Guard, M) -> Fut, + F: FnOnce(Guard, M) -> Fut, Fut: std::future::Future<Output = Res>, { match self.plugin.aquire_handles(handles_to_aquire) { |