From 83218c479a22a4578c3a12a56de6c4304ec399eb Mon Sep 17 00:00:00 2001 From: Sunny Gleason Date: Thu, 12 Dec 2019 14:55:30 -0500 Subject: [PATCH] code cleanup, storage_size() was Option, now Result (#7424) --- core/src/ledger_cleanup_service.rs | 2 +- ledger/src/blocktree.rs | 4 +--- ledger/src/blocktree_db.rs | 9 ++++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/src/ledger_cleanup_service.rs b/core/src/ledger_cleanup_service.rs index ba944169c..68e50414f 100644 --- a/core/src/ledger_cleanup_service.rs +++ b/core/src/ledger_cleanup_service.rs @@ -66,7 +66,7 @@ impl LedgerCleanupService { let disk_utilization_post = blocktree.storage_size(); - if let (Some(disk_utilization_pre), Some(disk_utilization_post)) = + if let (Ok(disk_utilization_pre), Ok(disk_utilization_post)) = (disk_utilization_pre, disk_utilization_post) { datapoint_debug!( diff --git a/ledger/src/blocktree.rs b/ledger/src/blocktree.rs index 170457881..f4ed93bb3 100644 --- a/ledger/src/blocktree.rs +++ b/ledger/src/blocktree.rs @@ -1499,9 +1499,7 @@ impl Blocktree { self.last_root() } - // return the approximate size in bytes of the storage directory, or `None` if an error occurs - // while reading the directory (directory not found, file deleted, etc) - pub fn storage_size(&self) -> Option { + pub fn storage_size(&self) -> Result { self.db.storage_size() } } diff --git a/ledger/src/blocktree_db.rs b/ledger/src/blocktree_db.rs index 641bcec95..6c1a0ff3b 100644 --- a/ledger/src/blocktree_db.rs +++ b/ledger/src/blocktree_db.rs @@ -1,7 +1,7 @@ use crate::blocktree_meta; use bincode::{deserialize, serialize}; use byteorder::{BigEndian, ByteOrder}; -use fs_extra::dir::get_size; +use fs_extra; use log::*; pub use rocksdb::Direction as IteratorDirection; use rocksdb::{ @@ -43,6 +43,7 @@ pub enum BlocktreeError { SlotNotRooted, IO(#[from] std::io::Error), Serialize(#[from] Box), + FsExtraError(#[from] fs_extra::error::Error), } pub(crate) type Result = std::result::Result; @@ -580,10 +581,8 @@ impl Database { self.backend.write(batch.write_batch) } - // return the approximate size in bytes of the storage directory, or `None` if an error occurs - // while reading the directory (directory not found, file deleted, etc) - pub fn storage_size(&self) -> Option { - get_size(&self.path).ok() + pub fn storage_size(&self) -> Result { + Ok(fs_extra::dir::get_size(&self.path)?) } }