1use std::{path::Path, time::Duration};
2
3use bon::bon;
4use tracing::warn;
5
6use crate::{
7 search,
8 wm::{EverythingClient, IpcError, RequestFlags},
9};
10
11#[bon]
12impl EverythingClient {
13 #[builder]
17 pub fn get_folder_size(
18 &self,
19 #[builder(start_fn)] path: &Path,
20 timeout: Option<Duration>,
21 ) -> Result<u64, IpcError> {
22 debug_assert_eq!(search::normalize_path_ev(path), path);
23 let search_query = format!(r#"wfn:"{}""#, path.display());
24
25 let query_list = self
26 .query_wait(&search_query)
27 .request_flags(RequestFlags::Size)
28 .maybe_timeout(timeout)
29 .call()
30 .inspect_err(|e| warn!(%e, ?path, "query failed"))?;
31
32 if let Some(item) = query_list.get(0) {
33 if let Some(size) = item.get_size(RequestFlags::Size) {
34 return Ok(size);
35 }
36 }
37 Err(IpcError::Query("folder not found"))
38 }
39}