mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
Add Windows support for storage monitor (#13466)
* Add Windows support for storage monitor * Apply suggested changes
This commit is contained in:
committed by
GitHub
parent
6aa4127a74
commit
a1c546e9aa
@@ -12,7 +12,7 @@ homepage = "https://substrate.io"
|
||||
clap = { version = "4.0.9", features = ["derive", "string"] }
|
||||
futures = "0.3.21"
|
||||
log = "0.4.17"
|
||||
nix = { version = "0.26.1", features = ["fs"] }
|
||||
fs4 = "0.6.3"
|
||||
sc-client-db = { version = "0.10.0-dev", default-features = false, path = "../db" }
|
||||
sc-utils = { version = "4.0.0-dev", path = "../utils" }
|
||||
sp-core = { version = "7.0.0", path = "../../primitives/core" }
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use clap::Args;
|
||||
use nix::{errno::Errno, sys::statvfs::statvfs};
|
||||
use sc_client_db::DatabaseSource;
|
||||
use sp_core::traits::SpawnEssentialNamed;
|
||||
use std::{
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
time::Duration,
|
||||
};
|
||||
@@ -31,7 +31,7 @@ const LOG_TARGET: &str = "storage-monitor";
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("IO Error")]
|
||||
IOError(#[from] Errno),
|
||||
IOError(#[from] io::Error),
|
||||
#[error("Out of storage space: available {0}MB, required {1}MB")]
|
||||
StorageOutOfSpace(u64, u64),
|
||||
}
|
||||
@@ -117,12 +117,7 @@ impl StorageMonitorService {
|
||||
|
||||
/// Returns free space in MB, or error if statvfs failed.
|
||||
fn free_space(path: &Path) -> Result<u64, Error> {
|
||||
statvfs(path)
|
||||
.map(|stats| {
|
||||
u64::from(stats.blocks_available()).saturating_mul(u64::from(stats.block_size())) /
|
||||
1_000_000
|
||||
})
|
||||
.map_err(Error::from)
|
||||
Ok(fs4::available_space(path).map(|s| s / 1_000_000)?)
|
||||
}
|
||||
|
||||
/// Checks if the amount of free space for given `path` is above given `threshold`.
|
||||
|
||||
Reference in New Issue
Block a user