From a57ee049c69ef973a9f4f8b24a3799a430c7899e Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Wed, 1 Feb 2023 19:09:45 +0100 Subject: [PATCH] Add a few comment --- mlar/src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mlar/src/main.rs b/mlar/src/main.rs index c828c72f..dfed49d8 100644 --- a/mlar/src/main.rs +++ b/mlar/src/main.rs @@ -5,6 +5,7 @@ use curve25519_parser::{ use glob::Pattern; use hkdf::Hkdf; use humansize::{FormatSize, DECIMAL}; +use lru::LruCache; use mla::config::{ArchiveReaderConfig, ArchiveWriterConfig}; use mla::errors::{Error, FailSafeReadError}; use mla::helpers::linear_extract; @@ -31,8 +32,6 @@ use std::path::{Component, Path, PathBuf}; use tar::{Builder, Header}; use zeroize::Zeroize; -use lru::LruCache; - // ----- Error ------ #[derive(Debug)] @@ -452,6 +451,7 @@ fn create_file>( struct FileWriter<'a> { /// Target file for data appending path: PathBuf, + /// Reference on the cache cache: &'a RefCell>, } @@ -465,9 +465,11 @@ impl<'a> Write for FileWriter<'a> { let file = fs::OpenOptions::new().append(true).open(&self.path)?; cache.put(self.path.clone(), file); } - // Safe to `unwrap` here cause we ensure the element is in the cache + // Safe to `unwrap` here cause we ensure the element is in the cache (mono-threaded) let file = cache.get_mut(&self.path).unwrap(); file.write(buf) + + // `file` will be closed on deletion from the cache } fn flush(&mut self) -> io::Result<()> {