Skip to content

Commit

Permalink
Add a few comment
Browse files Browse the repository at this point in the history
  • Loading branch information
commial committed Sep 29, 2023
1 parent 4299b81 commit a57ee04
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mlar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,8 +32,6 @@ use std::path::{Component, Path, PathBuf};
use tar::{Builder, Header};
use zeroize::Zeroize;

use lru::LruCache;

// ----- Error ------

#[derive(Debug)]
Expand Down Expand Up @@ -452,6 +451,7 @@ fn create_file<P1: AsRef<Path>>(
struct FileWriter<'a> {
/// Target file for data appending
path: PathBuf,
/// Reference on the cache
cache: &'a RefCell<LruCache<PathBuf, File>>,
}

Expand All @@ -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<()> {
Expand Down

0 comments on commit a57ee04

Please sign in to comment.