Skip to content

Commit 9e2fc4c

Browse files
sylvestreRenjiSann
authored andcommitted
df: use uucore parse_block_size for block size resolution
1 parent 04a8051 commit 9e2fc4c

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

src/uu/df/src/blocks.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
//! Types for representing and displaying block sizes.
66
use crate::{OPT_BLOCKSIZE, OPT_PORTABILITY};
77
use clap::ArgMatches;
8-
use std::{env, fmt};
8+
use std::fmt;
99

1010
use uucore::{
1111
display::Quotable,
12-
parser::parse_size::{
13-
IEC_BASES, ParseSizeError, SI_BASES, parse_size_non_zero_u64, parse_size_u64,
14-
},
12+
parser::parse_block_size,
13+
parser::parse_size::{IEC_BASES, ParseSizeError, SI_BASES, parse_size_u64},
1514
};
1615

1716
/// A `SuffixType` determines whether the suffixes are 1000 or 1024 based, and whether they are
@@ -157,11 +156,7 @@ impl BlockSize {
157156

158157
impl Default for BlockSize {
159158
fn default() -> Self {
160-
if env::var("POSIXLY_CORRECT").is_ok() {
161-
Self::Bytes(512)
162-
} else {
163-
Self::Bytes(1024)
164-
}
159+
Self::Bytes(parse_block_size::default_block_size())
165160
}
166161
}
167162

@@ -177,23 +172,15 @@ pub(crate) fn read_block_size(matches: &ArgMatches) -> Result<BlockSize, ParseSi
177172
}
178173
} else if matches.get_flag(OPT_PORTABILITY) {
179174
Ok(BlockSize::default())
180-
} else if let Some(bytes) = block_size_from_env() {
175+
} else if let Some(bytes) =
176+
parse_block_size::block_size_from_env(&["DF_BLOCK_SIZE", "BLOCK_SIZE", "BLOCKSIZE"]).found()
177+
{
181178
Ok(BlockSize::Bytes(bytes))
182179
} else {
183180
Ok(BlockSize::default())
184181
}
185182
}
186183

187-
fn block_size_from_env() -> Option<u64> {
188-
for env_var in ["DF_BLOCK_SIZE", "BLOCK_SIZE", "BLOCKSIZE"] {
189-
if let Ok(env_size) = env::var(env_var) {
190-
return parse_size_non_zero_u64(&env_size).ok();
191-
}
192-
}
193-
194-
None
195-
}
196-
197184
impl fmt::Display for BlockSize {
198185
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
199186
match self {

0 commit comments

Comments
 (0)