fix: 0B Node database size Windows

This commit is contained in:
Cyrix126 2024-10-11 18:19:17 +02:00
parent 0126a917c7
commit 7b87940425

View file

@ -4,7 +4,7 @@ use readable::byte::Byte;
use reqwest::Client; use reqwest::Client;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use std::fs::Metadata; use std::os::windows::fs::MetadataExt;
use std::{ use std::{
path::Path, path::Path,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
@ -414,13 +414,17 @@ impl PrivNodeApi {
.await? .await?
.json::<PrivNodeApi>() .json::<PrivNodeApi>()
.await?; .await?;
#[cfg(target_os = "windows")] // #[cfg(target_os = "windows")]
// api returns 0 for DB size for Windows so we read the size directly from the filesystem. // api returns 0 for DB size for Windows so we read the size directly from the filesystem.
// https://github.com/monero-project/monero/issues/9513 // https://github.com/monero-project/monero/issues/9513
{ {
private.result.database_size = std::fs::metadata(state.path_db) if let Ok(metadata) = std::fs::metadata(if !state.path_db.is_empty() {
.unwrap_or(".bitmonero") state.path_db.clone()
.st_size(); } else {
".bitmonero".to_string()
}) {
private.result.database_size = metadata.file_size();
}
} }
Ok(private) Ok(private)
} }