mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 02:46:29 +03:00
add number of files and bytes to get_info()
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -339,6 +339,24 @@ pub(crate) async fn dc_get_filebytes(context: &Context, path: impl AsRef<Path>)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn dc_get_dirbytes(context: &Context, path: impl AsRef<Path>) -> (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<Path>) -> bool {
|
||||
let path_abs = dc_get_abs_path(context, &path);
|
||||
if !path_abs.exists().await {
|
||||
|
||||
Reference in New Issue
Block a user