Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/uu/split/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn instantiate_current_writer(
input: &std::ffi::OsStr,
filename: &std::ffi::OsStr,
is_new: bool,
) -> std::io::Result<std::io::BufWriter<Box<dyn std::io::Write>>> {
) -> std::io::Result<Box<dyn std::io::Write>> {
// Refuse to truncate/overwrite the input. WASI cannot do the fd-based check
// unix/windows use, so this is a best-effort path comparison.
if paths_refer_to_same_file(input, filename) {
Expand All @@ -50,9 +50,7 @@ pub fn instantiate_current_writer(
.append(true)
.open(std::path::Path::new(filename))?
};
Ok(std::io::BufWriter::new(
Box::new(file) as Box<dyn std::io::Write>
))
Ok(Box::new(file) as Box<dyn std::io::Write>)
}

#[cfg(unix)]
Expand Down
10 changes: 5 additions & 5 deletions src/uu/split/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// file that was distributed with this source code.
use std::env;
use std::ffi::{OsStr, OsString};
use std::io::{BufWriter, Error, Result};
use std::io::{Error, Result};
use std::io::{ErrorKind, Write};
use std::path::Path;
use std::process::{Child, Command, Stdio};
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn instantiate_current_writer(
input: &OsStr,
filename: &OsStr,
is_new: bool,
) -> Result<BufWriter<Box<dyn Write>>> {
) -> Result<Box<dyn Write>> {
match filter {
None => {
let file = if is_new {
Expand All @@ -156,12 +156,12 @@ pub fn instantiate_current_writer(

file
};
Ok(BufWriter::new(Box::new(file) as Box<dyn Write>))
Ok(Box::new(file) as Box<dyn Write>)
}
Some(filter_command) => Ok(BufWriter::new(Box::new(
Some(filter_command) => Ok(Box::new(
// spawn a shell command and write to it
FilterWriter::new(filter_command, filename)?,
) as Box<dyn Write>)),
) as Box<dyn Write>),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/uu/split/src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use std::ffi::OsStr;
use std::io::{BufWriter, Error, Result};
use std::io::{Error, Result};
use std::io::{ErrorKind, Write};
use std::path::Path;
use uucore::display::Quotable;
Expand All @@ -19,7 +19,7 @@ pub fn instantiate_current_writer(
input: &OsStr,
filename: &OsStr,
is_new: bool,
) -> Result<BufWriter<Box<dyn Write>>> {
) -> Result<Box<dyn Write>> {
let file = if is_new {
create_or_truncate_output_file(input, filename)?
} else {
Expand All @@ -41,7 +41,7 @@ pub fn instantiate_current_writer(

file
};
Ok(BufWriter::new(Box::new(file) as Box<dyn Write>))
Ok(Box::new(file) as Box<dyn Write>)
}

fn create_or_truncate_output_file(input: &OsStr, filename: &OsStr) -> Result<std::fs::File> {
Expand Down
30 changes: 11 additions & 19 deletions src/uu/split/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::env;
use std::ffi::{OsStr, OsString};
use std::fs::{File, metadata};
use std::io;
use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Read, Seek, SeekFrom, Write, stdin};
use std::io::{BufRead, BufReader, ErrorKind, Read, Seek, SeekFrom, Write, stdin};
use std::path::Path;
use thiserror::Error;
use uucore::display::Quotable;
Expand Down Expand Up @@ -543,7 +543,7 @@ impl Settings {
&self,
filename: &OsStr,
is_new: bool,
) -> io::Result<BufWriter<Box<dyn Write>>> {
) -> io::Result<Box<dyn Write>> {
if platform::paths_refer_to_same_file(&self.input, filename) {
return Err(io::Error::other(
translate!("split-error-would-overwrite-input", "file" => filename.quote()),
Expand Down Expand Up @@ -710,7 +710,7 @@ struct ByteChunkWriter<'a> {
/// Once the number of bytes written to this writer exceeds
/// `chunk_size`, a new writer is initialized and assigned to this
/// field.
inner: BufWriter<Box<dyn Write>>,
inner: Box<dyn Write>,

/// Iterator that yields filenames for each chunk.
filename_iterator: FilenameIterator<'a>,
Expand Down Expand Up @@ -831,7 +831,7 @@ struct LineChunkWriter<'a> {
/// Once the number of lines written to this writer exceeds
/// `chunk_size`, a new writer is initialized and assigned to this
/// field.
inner: BufWriter<Box<dyn Write>>,
inner: Box<dyn Write>,

/// Iterator that yields filenames for each chunk.
filename_iterator: FilenameIterator<'a>,
Expand All @@ -854,7 +854,7 @@ impl<'a> LineChunkWriter<'a> {
fn start_new_chunk(
settings: &Settings,
filename_iterator: &mut FilenameIterator,
) -> io::Result<BufWriter<Box<dyn Write>>> {
) -> io::Result<Box<dyn Write>> {
let filename = filename_iterator.next().ok_or_else(|| {
io::Error::other(translate!("split-error-output-file-suffixes-exhausted"))
})?;
Expand Down Expand Up @@ -919,7 +919,7 @@ impl Write for LineChunkWriter<'_> {
/// Output file parameters
struct OutFile {
filename: OsString,
maybe_writer: Option<BufWriter<Box<dyn Write>>>,
maybe_writer: Option<Box<dyn Write>>,
is_new: bool,
}

Expand All @@ -932,7 +932,7 @@ trait ManageOutFiles {
&mut self,
idx: usize,
settings: &Settings,
) -> UResult<&mut BufWriter<Box<dyn Write>>>;
) -> UResult<&mut Box<dyn Write>>;
/// Initialize a new set of output files
/// Each [`OutFile`] is generated with filename, while the writer for it could be
/// optional, to be instantiated later by the calling function as needed.
Expand All @@ -951,11 +951,7 @@ trait ManageOutFiles {
/// are flagged as `is_new=false`, so they can be re-opened for appending
/// instead of created anew if we need to keep writing into them later,
/// i.e. in case of round robin distribution as in [`n_chunks_by_line_round_robin`]
fn get_writer(
&mut self,
idx: usize,
settings: &Settings,
) -> UResult<&mut BufWriter<Box<dyn Write>>>;
fn get_writer(&mut self, idx: usize, settings: &Settings) -> UResult<&mut Box<dyn Write>>;
}

impl ManageOutFiles for OutFiles {
Expand Down Expand Up @@ -1001,7 +997,7 @@ impl ManageOutFiles for OutFiles {
&mut self,
idx: usize,
settings: &Settings,
) -> UResult<&mut BufWriter<Box<dyn Write>>> {
) -> UResult<&mut Box<dyn Write>> {
let mut count = 0;
// Use-case for doing multiple tries of closing fds:
// E.g. split running in parallel to other processes (e.g. another split) doing similar stuff,
Expand Down Expand Up @@ -1048,11 +1044,7 @@ impl ManageOutFiles for OutFiles {
}
}

fn get_writer(
&mut self,
idx: usize,
settings: &Settings,
) -> UResult<&mut BufWriter<Box<dyn Write>>> {
fn get_writer(&mut self, idx: usize, settings: &Settings) -> UResult<&mut Box<dyn Write>> {
if self[idx].maybe_writer.is_some() {
Ok(self[idx].maybe_writer.as_mut().unwrap())
} else {
Expand Down Expand Up @@ -1472,7 +1464,7 @@ where
// to be overwritten for sure at the beginning of the loop below
// because we start with `remaining == 0`, indicating that a new
// chunk should start.
let mut writer: BufWriter<Box<dyn Write>> = BufWriter::new(Box::new(io::Cursor::new(vec![])));
let mut writer: Box<dyn Write> = Box::new(io::Cursor::new(vec![]));

let mut remaining = 0;
for line in lines_with_sep(reader, settings.separator) {
Expand Down
Loading