diff --git a/Cargo.lock b/Cargo.lock index 1aa3c3416..7a34ad49b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,12 +543,6 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" -[[package]] -name = "debug_print" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f215f9b7224f49fb73256115331f677d868b34d18b65dbe4db392e6021eea90" - [[package]] name = "diff" version = "0.1.12" @@ -1917,7 +1911,6 @@ version = "0.0.7" dependencies = [ "byte-unit", "clap", - "debug_print", "gcd", "libc", "signal-hook", diff --git a/src/uu/dd/Cargo.toml b/src/uu/dd/Cargo.toml index f65d0bf12..da0165245 100644 --- a/src/uu/dd/Cargo.toml +++ b/src/uu/dd/Cargo.toml @@ -17,7 +17,6 @@ path = "src/dd.rs" [dependencies] byte-unit = "4.0" clap = { version = "2.33", features = [ "wrap_help" ] } -debug_print = "1.0" gcd = "2.0" libc = "0.2" signal-hook = "0.3.9" diff --git a/src/uu/dd/cspell.json b/src/uu/dd/cspell.json index fb29630b2..4e47b090f 100644 --- a/src/uu/dd/cspell.json +++ b/src/uu/dd/cspell.json @@ -17,7 +17,9 @@ "fullblock", "noxfer", "iflag", + "iflags", "oflag", + "oflags", "infile", "outfile", "fileio", @@ -33,9 +35,30 @@ "datastructures", "creat", "mult", - "unfailed", "behaviour", "ctty", + "noatime", + "fname", + "fileout", + "ofile", + "doesnt", + "parseargs", + "rlen", + "wlen", + "rstat", + "wstat", + "rposition", + "btotal", + "sigval", + "sigusr", + "rmax", + "rsofar", + "rremain", + "bremain", + "oconvflags", + "fpath", + "testfile", + "specfile" ], "ignorePaths": [ "**/test-resources/*.test", diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 717c9d88b..d0faaacf7 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -24,6 +24,7 @@ use conversion_tables::*; use byte_unit::Byte; use clap::{self, crate_version}; use gcd::Gcd; +#[cfg(target_os = "linux")] use signal_hook::consts::signal; use std::cmp; use std::convert::TryInto; @@ -34,7 +35,9 @@ use std::io::{self, Read, Seek, Write}; #[cfg(target_os = "linux")] use std::os::unix::fs::OpenOptionsExt; use std::path::Path; -use std::sync::{atomic::AtomicUsize, atomic::Ordering, mpsc, Arc}; +#[cfg(target_os = "linux")] +use std::sync::atomic::Ordering; +use std::sync::{atomic::AtomicUsize, mpsc, Arc}; use std::thread; use std::time; @@ -168,15 +171,15 @@ impl Input { impl Read for Input { fn read(&mut self, buf: &mut [u8]) -> io::Result { let mut base_idx = 0; - let tlen = buf.len(); + let target_len = buf.len(); loop { match self.src.read(&mut buf[base_idx..]) { Ok(0) => return Ok(base_idx), Ok(rlen) if self.iflags.fullblock => { base_idx += rlen; - if base_idx >= tlen { - return Ok(tlen); + if base_idx >= target_len { + return Ok(target_len); } } Ok(len) => return Ok(len), @@ -707,6 +710,7 @@ fn gen_prog_updater(rx: mpsc::Receiver, print_level: Option bool { env::var("POSIXLY_CORRECT").is_ok() } @@ -731,21 +735,11 @@ fn gen_prog_updater(rx: mpsc::Receiver, print_level: Option { - reprint_prog_line(&update); - - update - } - (Ok(update), _) => update, - (Err(_), _) => { - // recv only fails permanently, so we break here to - // avoid recv'ing on a broken pipe - break; - } - }; + while let Ok(update) = rx.recv() { + // (Re)print status line if progress is requested. + if Some(StatusLevel::Progress) == print_level { + reprint_prog_line(&update); + } // Handle signals #[cfg(target_os = "linux")] if let SIGUSR1_USIZE = sigval.load(Ordering::Relaxed) { diff --git a/src/uu/dd/src/dd_unit_tests/block_unblock_tests.rs b/src/uu/dd/src/dd_unit_tests/block_unblock_tests.rs index 1b9698638..ca633906e 100644 --- a/src/uu/dd/src/dd_unit_tests/block_unblock_tests.rs +++ b/src/uu/dd/src/dd_unit_tests/block_unblock_tests.rs @@ -15,19 +15,15 @@ macro_rules! make_block_test ( print_level: None, count: None, cflags: IConvFlags { - ctable: None, block: $block, - unblock: None, - swab: false, - sync: None, - noerror: false, + ..IConvFlags::default() }, - iflags: DEFAULT_IFLAGS, + iflags: IFlags::default(), }, Output { dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(), obs: 512, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, $spec, format!("./test-resources/FAILED-{}.test", $test_name) @@ -47,19 +43,15 @@ macro_rules! make_unblock_test ( print_level: None, count: None, cflags: IConvFlags { - ctable: None, - block: None, unblock: $unblock, - swab: false, - sync: None, - noerror: false, + ..IConvFlags::default() }, - iflags: DEFAULT_IFLAGS, + iflags: IFlags::default(), }, Output { dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(), obs: 512, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, $spec, format!("./test-resources/FAILED-{}.test", $test_name) @@ -247,7 +239,11 @@ fn block_test_double_surrounded_nl_double_trunc() { make_block_test!( block_cbs16, "block-cbs-16", - File::open("./test-resources/dd-block-cbs16.test").unwrap(), + if cfg!(unix) { + File::open("./test-resources/dd-block-cbs16.test").unwrap() + } else { + File::open("./test-resources/dd-block-cbs16-win.test").unwrap() + }, Some(16), File::open("./test-resources/dd-block-cbs16.spec").unwrap() ); @@ -255,7 +251,11 @@ make_block_test!( make_block_test!( block_cbs16_as_cbs8, "block-cbs-16-as-cbs8", - File::open("./test-resources/dd-block-cbs16.test").unwrap(), + if cfg!(unix) { + File::open("./test-resources/dd-block-cbs16.test").unwrap() + } else { + File::open("./test-resources/dd-block-cbs16-win.test").unwrap() + }, Some(8), File::open("./test-resources/dd-block-cbs8.spec").unwrap() ); @@ -263,7 +263,11 @@ make_block_test!( make_block_test!( block_consecutive_nl, "block-consecutive-nl", - File::open("./test-resources/dd-block-consecutive-nl.test").unwrap(), + if cfg!(unix) { + File::open("./test-resources/dd-block-consecutive-nl.test").unwrap() + } else { + File::open("./test-resources/dd-block-consecutive-nl-win.test").unwrap() + }, Some(16), File::open("./test-resources/dd-block-consecutive-nl-cbs16.spec").unwrap() ); @@ -335,7 +339,11 @@ make_unblock_test!( "unblock-multi-16", File::open("./test-resources/dd-unblock-cbs16.test").unwrap(), Some(16), - File::open("./test-resources/dd-unblock-cbs16.spec").unwrap() + if cfg!(unix) { + File::open("./test-resources/dd-unblock-cbs16.spec").unwrap() + } else { + File::open("./test-resources/dd-unblock-cbs16-win.spec").unwrap() + } ); make_unblock_test!( @@ -343,5 +351,9 @@ make_unblock_test!( "unblock-multi-16-as-8", File::open("./test-resources/dd-unblock-cbs16.test").unwrap(), Some(8), - File::open("./test-resources/dd-unblock-cbs8.spec").unwrap() + if cfg!(unix) { + File::open("./test-resources/dd-unblock-cbs8.spec").unwrap() + } else { + File::open("./test-resources/dd-unblock-cbs8-win.spec").unwrap() + } ); diff --git a/src/uu/dd/src/dd_unit_tests/conv_sync_tests.rs b/src/uu/dd/src/dd_unit_tests/conv_sync_tests.rs index 8563985c6..945fbe7af 100644 --- a/src/uu/dd/src/dd_unit_tests/conv_sync_tests.rs +++ b/src/uu/dd/src/dd_unit_tests/conv_sync_tests.rs @@ -12,19 +12,15 @@ macro_rules! make_sync_test ( print_level: None, count: None, cflags: IConvFlags { - ctable: None, - block: None, - unblock: None, - swab: false, sync: $sync, - noerror: false, + ..IConvFlags::default() }, - iflags: DEFAULT_IFLAGS, + iflags: IFlags::default(), }, Output { dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(), obs: $obs, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, $spec, format!("./test-resources/FAILED-{}.test", $test_name) diff --git a/src/uu/dd/src/dd_unit_tests/conversion_tests.rs b/src/uu/dd/src/dd_unit_tests/conversion_tests.rs index 5276f38b3..d3a9229b6 100644 --- a/src/uu/dd/src/dd_unit_tests/conversion_tests.rs +++ b/src/uu/dd/src/dd_unit_tests/conversion_tests.rs @@ -12,12 +12,12 @@ macro_rules! make_conv_test ( print_level: None, count: None, cflags: icf!($ctable), - iflags: DEFAULT_IFLAGS, + iflags: IFlags::default(), }, Output { dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(), obs: 512, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, $spec, format!("./test-resources/FAILED-{}.test", $test_name) @@ -37,12 +37,12 @@ macro_rules! make_icf_test ( print_level: None, count: None, cflags: $icf, - iflags: DEFAULT_IFLAGS, + iflags: IFlags::default(), }, Output { dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(), obs: 512, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, $spec, format!("./test-resources/FAILED-{}.test", $test_name) @@ -142,13 +142,13 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test() { print_level: None, count: None, cflags: icf!(Some(&ASCII_TO_EBCDIC)), - iflags: DEFAULT_IFLAGS, + iflags: IFlags::default(), }; let o = Output { dst: File::create(&tmp_fname_ae).unwrap(), obs: 1024, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }; dd_fileout(i, o).unwrap(); @@ -164,13 +164,13 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test() { print_level: None, count: None, cflags: icf!(Some(&EBCDIC_TO_ASCII)), - iflags: DEFAULT_IFLAGS, + iflags: IFlags::default(), }; let o = Output { dst: File::create(&tmp_fname_ea).unwrap(), obs: 1024, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }; dd_fileout(i, o).unwrap(); diff --git a/src/uu/dd/src/dd_unit_tests/mod.rs b/src/uu/dd/src/dd_unit_tests/mod.rs index fc8836e11..90ef00eaf 100644 --- a/src/uu/dd/src/dd_unit_tests/mod.rs +++ b/src/uu/dd/src/dd_unit_tests/mod.rs @@ -9,34 +9,6 @@ use std::fs; use std::io::prelude::*; use std::io::BufReader; -const DEFAULT_CFO: OConvFlags = OConvFlags { - sparse: false, - excl: false, - nocreat: false, - notrunc: false, - fdatasync: false, - fsync: false, -}; - -const DEFAULT_IFLAGS: IFlags = IFlags { - cio: false, - direct: false, - directory: false, - dsync: false, - sync: false, - nocache: false, - nonblock: false, - noatime: false, - noctty: false, - nofollow: false, - nolinks: false, - binary: false, - text: false, - fullblock: false, - count_bytes: false, - skip_bytes: false, -}; - struct LazyReader { src: R, } @@ -50,19 +22,11 @@ impl Read for LazyReader { #[macro_export] macro_rules! icf ( - () => - { - icf!(None) - }; ( $ctable:expr ) => { IConvFlags { ctable: $ctable, - block: None, - unblock: None, - swab: false, - sync: None, - noerror: false, + ..IConvFlags::default() } }; ); @@ -84,13 +48,13 @@ macro_rules! make_spec_test ( ibs: 512, print_level: None, count: None, - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(), obs: 512, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, $spec, format!("./test-resources/FAILED-{}.test", $test_name) diff --git a/src/uu/dd/src/dd_unit_tests/sanity_tests.rs b/src/uu/dd/src/dd_unit_tests/sanity_tests.rs index fff942d26..1d0276cb3 100644 --- a/src/uu/dd/src/dd_unit_tests/sanity_tests.rs +++ b/src/uu/dd/src/dd_unit_tests/sanity_tests.rs @@ -52,13 +52,13 @@ make_io_test!( ibs: 521, print_level: None, count: None, - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: DST_PLACEHOLDER, obs: 1031, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test").unwrap() ); @@ -72,13 +72,13 @@ make_io_test!( ibs: 1031, print_level: None, count: None, - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: DST_PLACEHOLDER, obs: 521, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test").unwrap() ); @@ -92,13 +92,13 @@ make_io_test!( ibs: 1024, print_level: None, count: Some(CountType::Reads(32)), - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: DST_PLACEHOLDER, obs: 1024, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test").unwrap() ); @@ -112,13 +112,13 @@ make_io_test!( ibs: 531, print_level: None, count: Some(CountType::Bytes(32 * 1024)), - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: DST_PLACEHOLDER, obs: 1031, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test").unwrap() ); @@ -132,13 +132,13 @@ make_io_test!( ibs: 1024, print_level: None, count: Some(CountType::Reads(16)), - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: DST_PLACEHOLDER, obs: 1031, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/gnudd-deadbeef-first-16k.spec").unwrap() ); @@ -152,13 +152,13 @@ make_io_test!( ibs: 531, print_level: None, count: Some(CountType::Bytes(12345)), - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: DST_PLACEHOLDER, obs: 1031, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/gnudd-deadbeef-first-12345.spec").unwrap() ); @@ -172,13 +172,13 @@ make_io_test!( ibs: 1024, print_level: None, count: Some(CountType::Reads(32)), - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: DST_PLACEHOLDER, obs: 1024, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/gnudd-random-first-32k.spec").unwrap() ); @@ -192,13 +192,13 @@ make_io_test!( ibs: 521, print_level: None, count: Some(CountType::Bytes(32 * 1024)), - cflags: icf!(), - iflags: DEFAULT_IFLAGS, + cflags: IConvFlags::default(), + iflags: IFlags::default(), }, Output { dst: DST_PLACEHOLDER, obs: 1031, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/gnudd-random-first-32k.spec").unwrap() ); @@ -215,30 +215,16 @@ make_io_test!( ibs: 521, print_level: None, count: None, - cflags: icf!(), + cflags: IConvFlags::default(), iflags: IFlags { fullblock: true, - cio: false, - direct: false, - directory: false, - dsync: false, - sync: false, - nocache: false, - nonblock: false, - noatime: false, - noctty: false, - nofollow: false, - nolinks: false, - binary: false, - text: false, - count_bytes: false, - skip_bytes: false, + ..IFlags::default() }, }, Output { dst: DST_PLACEHOLDER, obs: 1031, - cflags: DEFAULT_CFO, + cflags: OConvFlags::default(), }, File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test").unwrap() ); @@ -316,7 +302,7 @@ fn bsize_test_bs_eq() { #[test] #[should_panic] -fn test_nocreate_causes_failure_when_ofile_doesnt_exist() { +fn test_nocreat_causes_failure_when_ofile_doesnt_exist() { let args = vec![ String::from("dd"), String::from("--conv=nocreat"), diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index c0e22c520..a27ab3cb0 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -186,7 +186,7 @@ impl std::str::FromStr for Flag { "direct" => // Ok(Self::Direct), { - if cfg!(unix) { + if cfg!(target_os = "linux") { Ok(Self::Direct) } else { Err(ParseError::Unimplemented(s.to_string())) @@ -195,7 +195,7 @@ impl std::str::FromStr for Flag { "directory" => // Ok(Self::Directory), { - if cfg!(unix) { + if cfg!(target_os = "linux") { Ok(Self::Directory) } else { Err(ParseError::Unimplemented(s.to_string())) @@ -204,7 +204,7 @@ impl std::str::FromStr for Flag { "dsync" => // Ok(Self::Dsync), { - if cfg!(unix) { + if cfg!(target_os = "linux") { Ok(Self::Dsync) } else { Err(ParseError::Unimplemented(s.to_string())) @@ -213,7 +213,7 @@ impl std::str::FromStr for Flag { "sync" => // Ok(Self::Sync), { - if cfg!(unix) { + if cfg!(target_os = "linux") { Ok(Self::Sync) } else { Err(ParseError::Unimplemented(s.to_string())) @@ -227,7 +227,7 @@ impl std::str::FromStr for Flag { "nonblock" => // Ok(Self::NonBlock), { - if cfg!(unix) { + if cfg!(target_os = "linux") { Ok(Self::NonBlock) } else { Err(ParseError::Unimplemented(s.to_string())) @@ -236,7 +236,7 @@ impl std::str::FromStr for Flag { "noatime" => // Ok(Self::NoATime), { - if cfg!(unix) { + if cfg!(target_os = "linux") { Ok(Self::NoATime) } else { Err(ParseError::Unimplemented(s.to_string())) @@ -245,7 +245,7 @@ impl std::str::FromStr for Flag { "noctty" => // Ok(Self::NoCtty), { - if cfg!(unix) { + if cfg!(target_os = "linux") { Ok(Self::NoCtty) } else { Err(ParseError::Unimplemented(s.to_string())) @@ -254,7 +254,7 @@ impl std::str::FromStr for Flag { "nofollow" => // Ok(Self::NoFollow), { - if cfg!(unix) { + if cfg!(target_os = "linux") { Ok(Self::NoFollow) } else { Err(ParseError::Unimplemented(s.to_string())) @@ -421,16 +421,13 @@ fn parse_flag_list>( /// Parse Conversion Options (Input Variety) /// Construct and validate a IConvFlags pub fn parse_conv_flag_input(matches: &Matches) -> Result { - let flags = parse_flag_list("conv", matches)?; - let cbs = parse_cbs(matches)?; - + let mut iconvflags = IConvFlags::default(); let mut fmt = None; let mut case = None; - let mut block = None; - let mut unblock = None; - let mut swab = false; - let mut sync = false; - let mut noerror = false; + let mut is_sync = false; + + let flags = parse_flag_list(options::CONV, matches)?; + let cbs = parse_cbs(matches)?; for flag in flags { match flag { @@ -469,27 +466,36 @@ pub fn parse_conv_flag_input(matches: &Matches) -> Result match (cbs, unblock) { - (Some(cbs), None) => block = Some(cbs), + ConvFlag::Block => match (cbs, iconvflags.unblock) { + (Some(cbs), None) => iconvflags.block = Some(cbs), (None, _) => return Err(ParseError::BlockUnblockWithoutCBS), (_, Some(_)) => return Err(ParseError::MultipleBlockUnblock), }, - ConvFlag::Unblock => match (cbs, block) { - (Some(cbs), None) => unblock = Some(cbs), + ConvFlag::Unblock => match (cbs, iconvflags.block) { + (Some(cbs), None) => iconvflags.unblock = Some(cbs), (None, _) => return Err(ParseError::BlockUnblockWithoutCBS), (_, Some(_)) => return Err(ParseError::MultipleBlockUnblock), }, - ConvFlag::Swab => swab = true, - ConvFlag::Sync => sync = true, - ConvFlag::NoError => noerror = true, + ConvFlag::Swab => iconvflags.swab = true, + ConvFlag::Sync => is_sync = true, + ConvFlag::NoError => iconvflags.noerror = true, _ => {} } } + // The final conversion table depends on both + // fmt (eg. ASCII -> EBCDIC) + // case (eg. UCASE -> LCASE) + // So the final value can't be set until all flags are parsed. let ctable = parse_ctable(fmt, case); - let sync = if sync && (block.is_some() || unblock.is_some()) { + + // The final value of sync depends on block/unblock + // block implies sync with ' ' + // unblock implies sync with 0 + // So the final value can't be set until all flags are parsed. + let sync = if is_sync && (iconvflags.block.is_some() || iconvflags.unblock.is_some()) { Some(b' ') - } else if sync { + } else if is_sync { Some(0u8) } else { None @@ -497,27 +503,17 @@ pub fn parse_conv_flag_input(matches: &Matches) -> Result Result { - let flags = parse_flag_list(options::CONV, matches)?; + let mut oconvflags = OConvFlags::default(); - let mut oconvflags = OConvFlags { - sparse: false, - excl: false, - nocreat: false, - notrunc: false, - fdatasync: false, - fsync: false, - }; + let flags = parse_flag_list(options::CONV, matches)?; for flag in flags { match flag { @@ -548,24 +544,7 @@ pub fn parse_conv_flag_output(matches: &Matches) -> Result Result { - let mut iflags = IFlags { - cio: false, - direct: false, - directory: false, - dsync: false, - sync: false, - nocache: false, - nonblock: false, - noatime: false, - noctty: false, - nofollow: false, - nolinks: false, - binary: false, - text: false, - fullblock: false, - count_bytes: false, - skip_bytes: false, - }; + let mut iflags = IFlags::default(); let flags = parse_flag_list(options::IFLAG, matches)?; @@ -596,23 +575,7 @@ pub fn parse_iflags(matches: &Matches) -> Result { /// Parse OFlags struct from CL-input pub fn parse_oflags(matches: &Matches) -> Result { - let mut oflags = OFlags { - append: false, - cio: false, - direct: false, - directory: false, - dsync: false, - sync: false, - nocache: false, - nonblock: false, - noatime: false, - noctty: false, - nofollow: false, - nolinks: false, - binary: false, - text: false, - seek_bytes: false, - }; + let mut oflags = OFlags::default(); let flags = parse_flag_list(options::OFLAG, matches)?; diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index 60b027bb6..765eb6f46 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -4,7 +4,7 @@ use crate::StatusLevel; #[cfg(not(target_os = "linux"))] #[test] -fn unimplemented_flags_should_error_non_unix() { +fn unimplemented_flags_should_error_non_linux() { let mut succeeded = Vec::new(); // The following flags are only implemented in linux @@ -518,29 +518,35 @@ test_byte_parser!(test_bytes_GB, "3GB", 3 * 1000 * 1000 * 1000); test_byte_parser!(test_bytes_G, "3G", 3 * 1024 * 1024 * 1024); test_byte_parser!(test_bytes_Gi, "3GiB", 3 * 1024 * 1024 * 1024); -test_byte_parser!(test_bytes_TB, "4TB", 4 * 1000 * 1000 * 1000 * 1000); -test_byte_parser!(test_bytes_T, "4T", 4 * 1024 * 1024 * 1024 * 1024); -test_byte_parser!(test_bytes_Ti, "4TiB", 4 * 1024 * 1024 * 1024 * 1024); +#[cfg(target_pointer_width = "64")] +#[cfg(test)] +mod test_64bit_arch { + use super::*; -test_byte_parser!(test_bytes_PB, "5PB", 5 * 1000 * 1000 * 1000 * 1000 * 1000); -test_byte_parser!(test_bytes_P, "5P", 5 * 1024 * 1024 * 1024 * 1024 * 1024); -test_byte_parser!(test_bytes_Pi, "5PiB", 5 * 1024 * 1024 * 1024 * 1024 * 1024); + test_byte_parser!(test_bytes_TB, "4TB", 4 * 1000 * 1000 * 1000 * 1000); + test_byte_parser!(test_bytes_T, "4T", 4 * 1024 * 1024 * 1024 * 1024); + test_byte_parser!(test_bytes_Ti, "4TiB", 4 * 1024 * 1024 * 1024 * 1024); -test_byte_parser!( - test_bytes_EB, - "6EB", - 6 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 -); -test_byte_parser!( - test_bytes_E, - "6E", - 6 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 -); -test_byte_parser!( - test_bytes_Ei, - "6EiB", - 6 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 -); + test_byte_parser!(test_bytes_PB, "5PB", 5 * 1000 * 1000 * 1000 * 1000 * 1000); + test_byte_parser!(test_bytes_P, "5P", 5 * 1024 * 1024 * 1024 * 1024 * 1024); + test_byte_parser!(test_bytes_Pi, "5PiB", 5 * 1024 * 1024 * 1024 * 1024 * 1024); + + test_byte_parser!( + test_bytes_EB, + "6EB", + 6 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + ); + test_byte_parser!( + test_bytes_E, + "6E", + 6 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 + ); + test_byte_parser!( + test_bytes_Ei, + "6EiB", + 6 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 + ); +} #[test] #[should_panic] diff --git a/src/uu/dd/test-resources/dd-block-cbs16-win.test b/src/uu/dd/test-resources/dd-block-cbs16-win.test new file mode 100644 index 000000000..9b51cb8f3 --- /dev/null +++ b/src/uu/dd/test-resources/dd-block-cbs16-win.test @@ -0,0 +1,16 @@ +0 +01 +012 +0123 +01234 +012345 +0123456 +01234567 +012345678 +0123456789 +0123456789a +0123456789ab +0123456789abc +0123456789abcd +0123456789abcde +0123456789abcdef diff --git a/src/uu/dd/test-resources/dd-block-consecutive-nl-win.test b/src/uu/dd/test-resources/dd-block-consecutive-nl-win.test new file mode 100644 index 000000000..1bf473b2b --- /dev/null +++ b/src/uu/dd/test-resources/dd-block-consecutive-nl-win.test @@ -0,0 +1,4 @@ +pre + + +post diff --git a/src/uu/dd/test-resources/dd-unblock-cbs16-win.spec b/src/uu/dd/test-resources/dd-unblock-cbs16-win.spec new file mode 100644 index 000000000..9b51cb8f3 --- /dev/null +++ b/src/uu/dd/test-resources/dd-unblock-cbs16-win.spec @@ -0,0 +1,16 @@ +0 +01 +012 +0123 +01234 +012345 +0123456 +01234567 +012345678 +0123456789 +0123456789a +0123456789ab +0123456789abc +0123456789abcd +0123456789abcde +0123456789abcdef diff --git a/src/uu/dd/test-resources/dd-unblock-cbs8-win.spec b/src/uu/dd/test-resources/dd-unblock-cbs8-win.spec new file mode 100644 index 000000000..8031036c1 --- /dev/null +++ b/src/uu/dd/test-resources/dd-unblock-cbs8-win.spec @@ -0,0 +1,32 @@ +0 + +01 + +012 + +0123 + +01234 + +012345 + +0123456 + +01234567 + +01234567 +8 +01234567 +89 +01234567 +89a +01234567 +89ab +01234567 +89abc +01234567 +89abcd +01234567 +89abcde +01234567 +89abcdef diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index a601190d9..e038ee24b 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -213,27 +213,12 @@ fn test_excl_causes_failure_when_present() { .fails(); } -#[cfg(target_os = "linux")] -#[test] -fn test_atime_updated() { - let fname = "this-file-exists-no-noatime.txt"; - assert_fixture_exists!(&fname); - - let (fix, mut ucmd) = at_and_ucmd!(); - ucmd.args(&["status=none", inf!(fname)]); - - let pre_atime = fix.metadata(fname).accessed().unwrap(); - - ucmd.pipe_in("").run().no_stderr().success(); - std::thread::sleep(std::time::Duration::from_millis(10)); - - let post_atime = fix.metadata(fname).accessed().unwrap(); - assert!(pre_atime != post_atime); -} - #[cfg(target_os = "linux")] #[test] fn test_noatime_does_not_update_infile_atime() { + // NOTE: Not all environments support tracking access time. If this + // test fails on some systems and passes on others, assume the functionality + // is not working and the systems that pass it simply don't update file access time. let fname = "this-ifile-exists-noatime.txt"; assert_fixture_exists!(&fname); @@ -251,6 +236,9 @@ fn test_noatime_does_not_update_infile_atime() { #[cfg(target_os = "linux")] #[test] fn test_noatime_does_not_update_ofile_atime() { + // NOTE: Not all environments support tracking access time. If this + // test fails on some systems and passes on others, assume the functionality + // is not working and the systems that pass it simply don't update file access time. let fname = "this-ofile-exists-noatime.txt"; assert_fixture_exists!(&fname); diff --git a/tests/fixtures/dd/cspell.json b/tests/fixtures/dd/cspell.json index 19986ad83..65fa927d6 100644 --- a/tests/fixtures/dd/cspell.json +++ b/tests/fixtures/dd/cspell.json @@ -1,6 +1,29 @@ { "version": "0.1", "language": "en", + "words": [ + "fname", + "fpath", + "specfile", + "testfile", + "iflag", + "iflags", + "oflag", + "oflags", + "noxfer", + "nocreat", + "noatime", + "infile", + "outfile", + "unspec", + "fullblock", + "urand", + "tname", + "fileio", + "gibi", + "ucase", + "lcase" + ], "ignorePaths": [ "*.txt", "*.spec"