mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
dd: move finalize() function to module level
Move the `finalize()` function out of the `impl Output` block and up to the module level so that it can be accessed by other module-level functions.
This commit is contained in:
parent
c99accc85f
commit
3faf64280d
1 changed files with 35 additions and 35 deletions
|
@ -632,7 +632,7 @@ impl<'a> Output<'a> {
|
||||||
// Optimization: if no blocks are to be written, then don't
|
// Optimization: if no blocks are to be written, then don't
|
||||||
// bother allocating any buffers.
|
// bother allocating any buffers.
|
||||||
if let Some(Num::Blocks(0) | Num::Bytes(0)) = i.settings.count {
|
if let Some(Num::Blocks(0) | Num::Bytes(0)) = i.settings.count {
|
||||||
return self.finalize(rstat, wstat, start, &prog_tx, output_thread);
|
return finalize(&mut self, rstat, wstat, start, &prog_tx, output_thread);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a common buffer with a capacity of the block size.
|
// Create a common buffer with a capacity of the block size.
|
||||||
|
@ -673,12 +673,13 @@ impl<'a> Output<'a> {
|
||||||
prog_tx.send(prog_update).unwrap_or(());
|
prog_tx.send(prog_update).unwrap_or(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.finalize(rstat, wstat, start, &prog_tx, output_thread)
|
finalize(&mut self, rstat, wstat, start, &prog_tx, output_thread)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Flush output, print final stats, and join with the progress thread.
|
/// Flush output, print final stats, and join with the progress thread.
|
||||||
fn finalize<T>(
|
fn finalize<T>(
|
||||||
&mut self,
|
output: &mut Output,
|
||||||
rstat: ReadStat,
|
rstat: ReadStat,
|
||||||
wstat: WriteStat,
|
wstat: WriteStat,
|
||||||
start: time::Instant,
|
start: time::Instant,
|
||||||
|
@ -686,7 +687,7 @@ impl<'a> Output<'a> {
|
||||||
output_thread: thread::JoinHandle<T>,
|
output_thread: thread::JoinHandle<T>,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
// Flush the output, if configured to do so.
|
// Flush the output, if configured to do so.
|
||||||
self.sync()?;
|
output.sync()?;
|
||||||
|
|
||||||
// Truncate the file to the final cursor location.
|
// Truncate the file to the final cursor location.
|
||||||
//
|
//
|
||||||
|
@ -696,8 +697,8 @@ impl<'a> Output<'a> {
|
||||||
// suppress the error by calling `Result::ok()`. This matches
|
// suppress the error by calling `Result::ok()`. This matches
|
||||||
// the behavior of GNU `dd` when given the command-line
|
// the behavior of GNU `dd` when given the command-line
|
||||||
// argument `of=/dev/null`.
|
// argument `of=/dev/null`.
|
||||||
if !self.settings.oconv.notrunc {
|
if !output.settings.oconv.notrunc {
|
||||||
self.dst.truncate().ok();
|
output.dst.truncate().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the final read/write statistics.
|
// Print the final read/write statistics.
|
||||||
|
@ -709,7 +710,6 @@ impl<'a> Output<'a> {
|
||||||
.expect("Failed to join with the output thread.");
|
.expect("Failed to join with the output thread.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
fn make_linux_oflags(oflags: &OFlags) -> Option<libc::c_int> {
|
fn make_linux_oflags(oflags: &OFlags) -> Option<libc::c_int> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue