From 073ef2776efecd64ffde9ac09d66cad578a7a13e Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 14:28:44 +0000 Subject: [PATCH] Returning result from delete_file function + some extra notes --- src/provider/storage/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/provider/storage/mod.rs b/src/provider/storage/mod.rs index 8df2a6f39e..090e12d1de 100644 --- a/src/provider/storage/mod.rs +++ b/src/provider/storage/mod.rs @@ -106,9 +106,9 @@ impl ClientStorage { }) .map(|entry| { let content = std::fs::read(entry.path()).unwrap(); - ClientStorage::delete_file(entry.path()); + ClientStorage::delete_file(entry.path()).unwrap(); content - }) // TODO: THIS MAP IS UNSAFE (BOTH READING AND DELETING)!! + }) // TODO: THIS MAP IS UNSAFE (BOTH FOR READING AND DELETING)!! - in the case where there are multiple requests from the same client being processed in parallel .chain(std::iter::repeat(ClientStorage::dummy_message())) .take(MESSAGE_RETRIEVAL_LIMIT) .collect(); @@ -121,8 +121,8 @@ impl ClientStorage { // TODO: THIS NEEDS A LOCKING MECHANISM!!! (or a db layer on top - basically 'ClientStorage' on steroids) // TODO 2: This should only be called AFTER we sent the reply. Because if client's connection failed after sending request // the messages would be deleted but he wouldn't have received them - fn delete_file(path: PathBuf) { + fn delete_file(path: PathBuf) -> io::Result<()> { println!("Here {:?} will be deleted!", path); - std::fs::remove_file(path); // another argument for db layer -> remove_file is NOT guaranteed to immediately get rid of the file + std::fs::remove_file(path) // another argument for db layer -> remove_file is NOT guaranteed to immediately get rid of the file } }