From 53886aad461104e8ea480fdc245fc0a7bc391b45 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Fri, 26 May 2023 23:43:23 +0100 Subject: [PATCH] Only produce warnings if files vanish during store --- yama/src/storing.rs | 16 ++++++++++++++-- yama_pile/src/tree.rs | 34 +++++++++++++++++----------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/yama/src/storing.rs b/yama/src/storing.rs index 9c06d2f..06bc841 100644 --- a/yama/src/storing.rs +++ b/yama/src/storing.rs @@ -6,6 +6,7 @@ use flume::{Receiver, RecvError, SendError, Sender}; use std::cmp::Reverse; use std::collections::{BTreeMap, BTreeSet}; use std::fmt::Debug; +use std::io; use std::io::Read; use std::path::{Path, PathBuf}; use std::pin::Pin; @@ -14,7 +15,7 @@ use tokio::fs::File; use tokio::runtime::Handle; use tokio::task; use tokio::task::JoinSet; -use tracing::{debug, error, info_span, Instrument}; +use tracing::{debug, error, info_span, warn, Instrument}; use yama_localcache::StoreConnection; use yama_midlevel_crypto::chunk_id::{ChunkId, ChunkIdKey}; use yama_pile::bloblogs::BloblogWriter; @@ -275,12 +276,23 @@ impl StoringState { } } +/// Stores a file, returning Ok(Some(...)) if fine, Ok(None) if the file doesn't exist (vanished) +/// or Err(...) for any other error. async fn store_file( file_path: &Path, storing_state: &mut StoringState, sbw: &mut StoringBloblogWriters, ) -> eyre::Result> { - let file = File::open(file_path).await?.into_std().await; + let file = match File::open(file_path).await { + Ok(file) => file.into_std().await, + Err(err) if err.kind() == io::ErrorKind::NotFound => { + warn!("file vanished: {file_path:?}"); + return Ok(None); + } + Err(other) => { + bail!("error storing {file_path:?}: {other:?}"); + } + }; let mapped = unsafe { memmap2::Mmap::map(&file) }?; let size_of_file = mapped.as_ref().len(); let chunkref = storing_state.store_full_slice(mapped.as_ref(), sbw)?; diff --git a/yama_pile/src/tree.rs b/yama_pile/src/tree.rs index 0641d03..945a52d 100644 --- a/yama_pile/src/tree.rs +++ b/yama_pile/src/tree.rs @@ -409,25 +409,25 @@ pub fn assemble_tree_from_scan_entries( permissions, size: _unverified_size_ignore, } => { - let (content, size) = chunkings + if let Some((content, size)) = chunkings .remove(&key_string) .with_context(|| format!("bad chunkings PMap: missing entry: {key_string:?}"))? - .unwrap(); // TODO - - // note: for the root, this inserts the root file entry as a child called "" within a fake root 'directory'. - // That's fine. We'll patch this up later. - dirs.get_mut(parent_dir_name) - .context("bad PMap: parent not seen first")? - .insert( - child_name.to_owned(), - TreeNode::NormalFile { - mtime, - ownership, - permissions, - size, - content, - }, - ); + { + // note: for the root, this inserts the root file entry as a child called "" within a fake root 'directory'. + // That's fine. We'll patch this up later. + dirs.get_mut(parent_dir_name) + .context("bad PMap: parent not seen first")? + .insert( + child_name.to_owned(), + TreeNode::NormalFile { + mtime, + ownership, + permissions, + size, + content, + }, + ); + } } ScanEntry::Directory { ownership,