Skip to content

Commit

Permalink
calculate and display transfer saves
Browse files Browse the repository at this point in the history
  • Loading branch information
djugei committed Apr 4, 2024
1 parent ee512ba commit 95b3777
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,12 @@ fn upgrade(server: Url, delta_cache: PathBuf, multi: MultiProgress) -> anyhow::R
})
.await??;
}
use std::os::unix::fs::MetadataExt;
let deltasize = deltafile.metadata().await?.size();
let newsize = tokio::fs::File::open(&file_name).await?.metadata().await?.size();

total_pg.inc(dec_size);
Ok::<(), anyhow::Error>(())
Ok::<_, anyhow::Error>((deltasize, newsize))
};

let sigfut = async {
Expand All @@ -312,18 +316,33 @@ fn upgrade(server: Url, delta_cache: PathBuf, multi: MultiProgress) -> anyhow::R
};

let (f, s) = tokio::join!(filefut, sigfut);
f.context("creating delat file failed")?;
let f = f.context("creating delta file failed")?;
s.context("creating signature file failed")?;
Ok::<(), anyhow::Error>(())
Ok::<_, anyhow::Error>(f)
});
}

let mut deltasize = 0;
let mut newsize = 0;
while let Some(res) = set.join_next().await {
if let Err(e) = res {
error!("{}", e);
error!("if the error is temporary, you can try running the command again");
match res.unwrap() {
Err(e) => {
error!("{}", e);
error!("if the error is temporary, you can try running the command again");
}
Ok((d, n)) => {
deltasize += d;
newsize += n;
}
}
}
static MB: u64 = 1024 * 1024;
deltasize /= MB;
newsize /= MB;
let saved = newsize - deltasize;
info!("downloaded {deltasize}MB");
info!("upgrades are {newsize}MB");
info!("saved you {saved}MB");
});
Ok(())
}
Expand Down

0 comments on commit 95b3777

Please sign in to comment.