Merge pull request #305 from cakebaker/mcookie_dont_use_option_for_max_size
mcookie: don't use `Option` for `max_size`
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::FileTypeExt;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{stdin, Read},
|
||||
@@ -51,14 +49,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
if s == 0 {
|
||||
s = MAX_DEFAULT;
|
||||
}
|
||||
Some(s)
|
||||
s
|
||||
}
|
||||
Err(_) => {
|
||||
return Err(USimpleError::new(1, "Failed to parse max-size value"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Some(MAX_DEFAULT)
|
||||
MAX_DEFAULT
|
||||
};
|
||||
|
||||
let mut hasher = Md5::new();
|
||||
@@ -69,14 +67,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
|
||||
if file_path == "-" {
|
||||
input_name = "stdin";
|
||||
let mut stdin_handle = stdin();
|
||||
let stdin_handle = stdin();
|
||||
|
||||
if let Some(max_bytes) = &max_size {
|
||||
let mut limited_reader = stdin_handle.take(*max_bytes);
|
||||
let mut limited_reader = stdin_handle.take(max_size);
|
||||
limited_reader.read_to_end(&mut buffer)?;
|
||||
} else {
|
||||
stdin_handle.read_to_end(&mut buffer)?;
|
||||
}
|
||||
} else {
|
||||
input_name = file_path;
|
||||
let open_result = File::open(file_path);
|
||||
@@ -85,28 +79,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut f = open_result.unwrap();
|
||||
if let Some(max_bytes) = &max_size {
|
||||
let mut limited_reader = f.take(*max_bytes);
|
||||
let f = open_result.unwrap();
|
||||
let mut limited_reader = f.take(max_size);
|
||||
limited_reader.read_to_end(&mut buffer)?;
|
||||
} else {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
const DEFAULT_SEED_READ_BYTES: u64 = 1024;
|
||||
let metadata = f.metadata()?;
|
||||
|
||||
if metadata.file_type().is_char_device() {
|
||||
let mut handle = f.take(DEFAULT_SEED_READ_BYTES);
|
||||
handle.read_to_end(&mut buffer)?;
|
||||
} else {
|
||||
f.read_to_end(&mut buffer)?;
|
||||
}
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
f.read_to_end(&mut buffer)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if verbose {
|
||||
|
||||
Reference in New Issue
Block a user