Skip to content

Commit

Permalink
Add Windows support for storage monitor (paritytech#13466)
Browse files Browse the repository at this point in the history
* Add Windows support for storage monitor

* Apply suggested changes
  • Loading branch information
ark0f authored and nathanwhit committed Jul 19, 2023
1 parent e7cc6b7 commit 97b4023
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
57 changes: 47 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/storage-monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
11 changes: 3 additions & 8 deletions client/storage-monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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),
}
Expand Down Expand Up @@ -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`.
Expand Down

0 comments on commit 97b4023

Please sign in to comment.