fix display for AddDir + fix AddDir counter

This commit is contained in:
Mark 2024-12-24 02:02:51 +01:00
parent 6172ffe248
commit 209821820b
4 changed files with 43 additions and 34 deletions

View File

@ -100,7 +100,8 @@ pub fn apply_indexchanges_int(
);
for (i, change) in changes.iter().enumerate() {
match change {
IndexChange::AddDir(dir, _) => {
IndexChange::AddDir(dir, make_new, _) => {
if *make_new {
let ok = if let Some(target) = target {
let t = target.join(dir);
if let Err(e) = fs::create_dir_all(&t) {
@ -116,6 +117,7 @@ pub fn apply_indexchanges_int(
fs::create_dir_all(&index.join(dir))?;
}
}
}
IndexChange::AddFile(file, index_file) => {
gib_transferred += index_file.size as f64 / (1024 * 1024 * 1024) as f64;
let ok = if let Some(target) = target {

View File

@ -5,7 +5,7 @@ use crate::indexfile::IndexFile;
#[derive(Debug)]
pub enum IndexChange {
/// Ensure a directory with this path exists (at least if all its parent directories exist).
AddDir(PathBuf, u64),
AddDir(PathBuf, bool, u64),
/// Add or update a file
AddFile(PathBuf, IndexFile),
/// Remove a file

View File

@ -108,14 +108,15 @@ fn main() {
}
fn show_change(change: &IndexChange, rev: bool) {
match change {
IndexChange::AddDir(v, s) => {
IndexChange::AddDir(v, new, s) => {
let mut path_str = v.display().to_string();
if !path_str.ends_with(['/', '\\']) {
path_str.push('/');
}
eprintln!(
"{}>> {} [{:.2} GiB]",
" {}{} {} [{:.2} GiB]",
if rev { "^" } else { "v" },
if *new { ">>" } else { "> " },
path_str,
*s as f64 / (1024 * 1024 * 1024) as f64
);
@ -138,7 +139,7 @@ fn main() {
eprintln!(" - - - - -");
let add_dir_count = changes
.iter()
.filter(|c| matches!(c, IndexChange::AddDir(..)))
.filter(|c| matches!(c, IndexChange::AddDir(_, true, _)))
.count();
eprintln!(
" {}>> add directory | {add_dir_count}x",

View File

@ -91,10 +91,10 @@ fn rec(
let mut total_size = 0;
// used to find removals
let index_rel_path = index_files.join(rel_path);
let mut index_entries = match fs::read_dir(&index_rel_path) {
Err(_) => HashMap::new(),
Ok(e) => e
.into_iter()
let (mut index_entries, dir_is_new) = match fs::read_dir(&index_rel_path) {
Err(_) => (HashMap::new(), true),
Ok(e) => (
e.into_iter()
.filter_map(|v| v.ok())
.map(|v| {
Ok((
@ -105,6 +105,8 @@ fn rec(
))
})
.collect::<Result<_, (String, PathBuf, io::Error)>>()?,
false,
),
};
// compare source files with index
let source_files_path = source.join(rel_path);
@ -182,7 +184,11 @@ fn rec(
}
}
// combine everything
let changes = [IndexChange::AddDir(rel_path.to_path_buf(), total_size)]
let changes = [IndexChange::AddDir(
rel_path.to_path_buf(),
dir_is_new,
total_size,
)]
.into_iter()
.chain(removals.into_iter())
.chain(ichanges.into_iter().flat_map(|(_, v)| v))