diff --git a/src/context.rs b/src/context.rs index 8fdcaee54..5a23a38c3 100644 --- a/src/context.rs +++ b/src/context.rs @@ -12,7 +12,7 @@ use crate::chat::*; use crate::config::Config; use crate::constants::*; use crate::contact::*; -use crate::dc_tools::{dc_get_filebytes, duration_to_str}; +use crate::dc_tools::{dc_get_dirbytes, dc_get_filebytes, duration_to_str}; use crate::error::*; use crate::events::{Event, EventEmitter, EventType, Events}; use crate::key::{DcKey, SignedPublicKey}; @@ -262,6 +262,9 @@ impl Context { ******************************************************************************/ pub async fn get_info(&self) -> BTreeMap<&'static str, String> { + let blobdir = self.get_blobdir(); + let (blobdir_files, blobdir_bytes) = dc_get_dirbytes(self, blobdir).await; + let unset = "0"; let l = LoginParam::from_database(self, "").await; let l2 = LoginParam::from_database(self, "configured_").await; @@ -330,7 +333,9 @@ impl Context { dc_get_filebytes(self, self.get_dbfile()).await.to_string(), ); res.insert("journal_mode", journal_mode); - res.insert("blobdir", self.get_blobdir().display().to_string()); + res.insert("blobdir", blobdir.display().to_string()); + res.insert("blobdir_files", blobdir_files.to_string()); + res.insert("blobdir_bytes", blobdir_bytes.to_string()); res.insert("display_name", displayname.unwrap_or_else(|| unset.into())); res.insert( "selfavatar", diff --git a/src/dc_tools.rs b/src/dc_tools.rs index 7c64e7c9d..f6cff90c6 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -339,6 +339,24 @@ pub(crate) async fn dc_get_filebytes(context: &Context, path: impl AsRef) } } +pub(crate) async fn dc_get_dirbytes(context: &Context, path: impl AsRef) -> (usize, u64) { + let path_abs = dc_get_abs_path(context, &path); + let mut files: usize = 0; + let mut bytes: u64 = 0; + if let Ok(mut read_dir) = async_std::fs::read_dir(path_abs).await { + while let Some(entry) = read_dir.next().await { + if let Ok(entry) = entry { + files += 1; + bytes += match entry.metadata().await { + Ok(meta) => meta.len(), + Err(_err) => 0, + } + } + } + } + (files, bytes) +} + pub(crate) async fn dc_delete_file(context: &Context, path: impl AsRef) -> bool { let path_abs = dc_get_abs_path(context, &path); if !path_abs.exists().await {