diff --git a/src/bin/pdata_tools.rs b/src/bin/pdata_tools.rs index 0ba337c..8dc8cc7 100644 --- a/src/bin/pdata_tools.rs +++ b/src/bin/pdata_tools.rs @@ -23,7 +23,7 @@ fn main_() -> Result<()> { let mut new_args = vec![OsString::from(&name)]; for a in args.into_iter() { - new_args.push(OsString::from(a)); + new_args.push(a); } if name_eq(name, "cache_check") { diff --git a/src/bin/thin_explore.rs b/src/bin/thin_explore.rs index 26776ab..1ca50c4 100644 --- a/src/bin/thin_explore.rs +++ b/src/bin/thin_explore.rs @@ -266,7 +266,7 @@ impl<'a> Widget for HeaderWidget<'a> { fn read_node(engine: &dyn IoEngine, loc: u64) -> Result> { let b = engine.read(loc)?; let path = Vec::new(); - btree::unpack_node(&path, &b.get_data(), true, false) + btree::unpack_node(&path, b.get_data(), true, false) .map_err(|_| anyhow!("couldn't unpack btree node")) } @@ -765,7 +765,7 @@ fn perform_action( } fn explore(path: &Path, node_path: Option>) -> Result<()> { - let engine = SyncIoEngine::new(&path, 1, false)?; + let engine = SyncIoEngine::new(path, 1, false)?; let mut panels: Vec> = Vec::new(); @@ -861,7 +861,7 @@ fn main() -> Result<()> { .map(|text| btree::decode_node_path(text).unwrap()); let input_file = Path::new(matches.value_of("INPUT").unwrap()); - explore(&input_file, node_path) + explore(input_file, node_path) } //------------------------------------ diff --git a/src/cache/check.rs b/src/cache/check.rs index 17632cc..66e9c22 100644 --- a/src/cache/check.rs +++ b/src/cache/check.rs @@ -92,10 +92,10 @@ mod format1 { let mut errs: Vec = Vec::new(); for m in b.values.iter() { - if let Err(e) = self.check_flags(&m) { + if let Err(e) = self.check_flags(m) { errs.push(e); } - if let Err(e) = self.check_oblock(&m) { + if let Err(e) = self.check_oblock(m) { errs.push(e); } } @@ -182,10 +182,10 @@ mod format2 { let cbegin = index as u32 * b.header.max_entries; let cend = cbegin + b.header.nr_entries; for (m, cblock) in b.values.iter().zip(cbegin..cend) { - if let Err(e) = self.check_flags(&m, inner.dirty_bits.contains(cblock as usize)) { + if let Err(e) = self.check_flags(m, inner.dirty_bits.contains(cblock as usize)) { errs.push(e); } - if let Err(e) = self.check_oblock(&m, &mut inner.seen_oblocks) { + if let Err(e) = self.check_oblock(m, &mut inner.seen_oblocks) { errs.push(e); } } @@ -271,7 +271,7 @@ pub fn check(opts: CacheCheckOptions) -> anyhow::Result<()> { let sb = match read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION) { Ok(sb) => sb, Err(e) => { - check_not_xml(&opts.dev, &opts.report); + check_not_xml(opts.dev, &opts.report); return Err(e); } }; diff --git a/src/cache/superblock.rs b/src/cache/superblock.rs index abe9b5d..2df3679 100644 --- a/src/cache/superblock.rs +++ b/src/cache/superblock.rs @@ -96,7 +96,7 @@ fn unpack(data: &[u8]) -> IResult<&[u8], Superblock> { if version >= 2 { let (m, root) = le_u64(i)?; dirty_root = Some(root); - i = &m; + i = m; } Ok(( diff --git a/src/commands/cache_check.rs b/src/commands/cache_check.rs index 9c74a34..6435425 100644 --- a/src/commands/cache_check.rs +++ b/src/commands/cache_check.rs @@ -7,8 +7,8 @@ use std::process; use std::sync::Arc; use crate::cache::check::{check, CacheCheckOptions}; -use crate::report::*; use crate::commands::utils::*; +use crate::report::*; //------------------------------------------ @@ -76,7 +76,7 @@ pub fn run(args: &[std::ffi::OsString]) { check_file_not_tiny(input_file, &report); let opts = CacheCheckOptions { - dev: &input_file, + dev: input_file, async_io: matches.is_present("ASYNC_IO"), sb_only: matches.is_present("SB_ONLY"), skip_mappings: matches.is_present("SKIP_MAPPINGS"), diff --git a/src/commands/cache_repair.rs b/src/commands/cache_repair.rs index fd569a8..e9d8a03 100644 --- a/src/commands/cache_repair.rs +++ b/src/commands/cache_repair.rs @@ -60,8 +60,8 @@ pub fn run(args: &[std::ffi::OsString]) { check_input_file(input_file, &report); let opts = CacheRepairOptions { - input: &input_file, - output: &output_file, + input: input_file, + output: output_file, async_io: matches.is_present("ASYNC_IO"), report: report.clone(), }; diff --git a/src/commands/cache_restore.rs b/src/commands/cache_restore.rs index f40c86c..f3b6826 100644 --- a/src/commands/cache_restore.rs +++ b/src/commands/cache_restore.rs @@ -51,8 +51,8 @@ pub fn run(args: &[std::ffi::OsString]) { check_output_file(output_file, &report); let opts = CacheRestoreOptions { - input: &input_file, - output: &output_file, + input: input_file, + output: output_file, async_io: matches.is_present("ASYNC_IO"), report: report.clone(), }; diff --git a/src/commands/thin_check.rs b/src/commands/thin_check.rs index 01135d7..f653649 100644 --- a/src/commands/thin_check.rs +++ b/src/commands/thin_check.rs @@ -5,9 +5,9 @@ use std::path::Path; use std::process; use std::sync::Arc; +use crate::commands::utils::*; use crate::io_engine::*; use crate::thin::check::{check, ThinCheckOptions, MAX_CONCURRENT_IO}; -use crate::commands::utils::*; pub fn run(args: &[std::ffi::OsString]) { let parser = App::new("thin_check") @@ -88,7 +88,7 @@ pub fn run(args: &[std::ffi::OsString]) { .index(1), ); - let matches = parser.get_matches_from(args.into_iter()); + let matches = parser.get_matches_from(args.iter()); let input_file = Path::new(matches.value_of("INPUT").unwrap()); let report = mk_report(matches.is_present("QUIET")); @@ -101,14 +101,13 @@ pub fn run(args: &[std::ffi::OsString]) { if matches.is_present("ASYNC_IO") { engine = Arc::new( - AsyncIoEngine::new(&input_file, MAX_CONCURRENT_IO, writable) + AsyncIoEngine::new(input_file, MAX_CONCURRENT_IO, writable) .expect("unable to open input file"), ); } else { let nr_threads = std::cmp::max(8, num_cpus::get() * 2); engine = Arc::new( - SyncIoEngine::new(&input_file, nr_threads, writable) - .expect("unable to open input file"), + SyncIoEngine::new(input_file, nr_threads, writable).expect("unable to open input file"), ); } diff --git a/src/commands/thin_metadata_pack.rs b/src/commands/thin_metadata_pack.rs index 8b4cfa4..cc40189 100644 --- a/src/commands/thin_metadata_pack.rs +++ b/src/commands/thin_metadata_pack.rs @@ -31,7 +31,7 @@ pub fn run(args: &[std::ffi::OsString]) { let report = std::sync::Arc::new(mk_simple_report()); check_input_file(input_file, &report); - if let Err(reason) = crate::pack::toplevel::pack(&input_file, &output_file) { + if let Err(reason) = crate::pack::toplevel::pack(input_file, output_file) { report.fatal(&format!("Application error: {}\n", reason)); exit(1); } diff --git a/src/commands/thin_metadata_unpack.rs b/src/commands/thin_metadata_unpack.rs index 6a2cf8d..4dbb2b2 100644 --- a/src/commands/thin_metadata_unpack.rs +++ b/src/commands/thin_metadata_unpack.rs @@ -1,9 +1,9 @@ extern crate clap; +use crate::file_utils; use clap::{App, Arg}; use std::path::Path; use std::process; -use crate::file_utils; use std::process::exit; @@ -37,7 +37,7 @@ pub fn run(args: &[std::ffi::OsString]) { exit(1); } - if let Err(reason) = crate::pack::toplevel::unpack(&input_file, &output_file) { + if let Err(reason) = crate::pack::toplevel::unpack(input_file, output_file) { eprintln!("Application error: {}", reason); process::exit(1); } diff --git a/src/commands/thin_repair.rs b/src/commands/thin_repair.rs index 39ce159..ee604e7 100644 --- a/src/commands/thin_repair.rs +++ b/src/commands/thin_repair.rs @@ -91,8 +91,8 @@ pub fn run(args: &[std::ffi::OsString]) { }); let opts = ThinRepairOptions { - input: &input_file, - output: &output_file, + input: input_file, + output: output_file, async_io: matches.is_present("ASYNC_IO"), report: report.clone(), overrides: SuperblockOverrides { diff --git a/src/commands/thin_restore.rs b/src/commands/thin_restore.rs index b694304..9742034 100644 --- a/src/commands/thin_restore.rs +++ b/src/commands/thin_restore.rs @@ -51,8 +51,8 @@ pub fn run(args: &[std::ffi::OsString]) { check_output_file(output_file, &report); let opts = ThinRestoreOptions { - input: &input_file, - output: &output_file, + input: input_file, + output: output_file, async_io: matches.is_present("ASYNC_IO"), report: report.clone(), }; diff --git a/src/commands/thin_shrink.rs b/src/commands/thin_shrink.rs index 5d04f85..a19a76c 100644 --- a/src/commands/thin_shrink.rs +++ b/src/commands/thin_shrink.rs @@ -70,7 +70,7 @@ pub fn run(args: &[std::ffi::OsString]) { check_input_file(input_file, &report); if let Err(reason) = - crate::shrink::toplevel::shrink(&input_file, &output_file, &data_file, size, do_copy) + crate::shrink::toplevel::shrink(input_file, output_file, data_file, size, do_copy) { eprintln!("Application error: {}\n", reason); exit(1); diff --git a/src/commands/utils.rs b/src/commands/utils.rs index 4e5de06..f7a9a2a 100644 --- a/src/commands/utils.rs +++ b/src/commands/utils.rs @@ -10,10 +10,7 @@ use crate::report::*; pub fn check_input_file(input_file: &Path, report: &Report) { if !file_utils::file_exists(input_file) { - report.fatal(&format!( - "Couldn't find input file '{:?}'.", - &input_file - )); + report.fatal(&format!("Couldn't find input file '{:?}'.", &input_file)); exit(1); } @@ -62,15 +59,11 @@ pub fn mk_report(quiet: bool) -> std::sync::Arc { } fn is_xml(line: &[u8]) -> bool { - line.starts_with(b" Result<()> { - let mut file = OpenOptions::new() - .read(true) - .open(input_file)?; + let mut file = OpenOptions::new().read(true).open(input_file)?; let mut data = vec![0; 16]; file.read_exact(&mut data)?; diff --git a/src/file_utils.rs b/src/file_utils.rs index 6c06819..40d1b30 100644 --- a/src/file_utils.rs +++ b/src/file_utils.rs @@ -18,28 +18,19 @@ pub fn is_file_or_blk_(info: FileStat) -> bool { } pub fn file_exists(path: &Path) -> bool { - match stat::stat(path) { - Ok(_) => true, - _ => false, - } + matches!(stat::stat(path), Ok(_)) } pub fn is_file_or_blk(path: &Path) -> bool { match stat::stat(path) { - Ok(info) =>is_file_or_blk_(info), + Ok(info) => is_file_or_blk_(info), _ => false, } } pub fn is_file(path: &Path) -> bool { match stat::stat(path) { - Ok(info) => { - if test_bit(info.st_mode, SFlag::S_IFREG) { - true - } else { - false - } - } + Ok(info) => test_bit(info.st_mode, SFlag::S_IFREG), _ => false, } } @@ -113,5 +104,3 @@ pub fn create_sized_file(path: &Path, nr_bytes: u64) -> io::Result Deref for FileGuard<'a> { type Target = File; fn deref(&self) -> &File { - &self.file.as_ref().expect("empty file guard") + self.file.as_ref().expect("empty file guard") } } @@ -180,7 +180,7 @@ impl SyncIoEngine { fn write_(output: &mut File, b: &Block) -> Result<()> { output.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?; - output.write_all(&b.get_data())?; + output.write_all(b.get_data())?; Ok(()) } } diff --git a/src/pack/toplevel.rs b/src/pack/toplevel.rs index 2298cea..0f78868 100644 --- a/src/pack/toplevel.rs +++ b/src/pack/toplevel.rs @@ -66,7 +66,7 @@ fn mk_chunk_vecs(nr_blocks: u64, nr_jobs: u64) -> Vec> { } pub fn pack(input_file: &Path, output_file: &Path) -> Result<(), Box> { - let nr_blocks = get_nr_blocks(&input_file)?; + let nr_blocks = get_nr_blocks(input_file)?; let nr_jobs = std::cmp::max(1, std::cmp::min(num_cpus::get() as u64, nr_blocks / 128)); let chunk_vecs = mk_chunk_vecs(nr_blocks, nr_jobs); @@ -122,7 +122,7 @@ where let kind = metadata_block_type(data); if kind != BT::UNKNOWN { z.write_u64::(b)?; - pack_block(&mut z, kind, &data)?; + pack_block(&mut z, kind, data)?; written += 1; if written == 1024 { diff --git a/src/pack/vm.rs b/src/pack/vm.rs index dc55e0e..d5c1602 100644 --- a/src/pack/vm.rs +++ b/src/pack/vm.rs @@ -442,7 +442,7 @@ mod tests { let mut r = Cursor::new(&mut bs); let unpacked = unpack(&mut r, ns.len() * 8).unwrap(); - check_u64s_match(&ns, &unpacked[0..]) + check_u64s_match(ns, &unpacked[0..]) } #[test] @@ -457,7 +457,7 @@ mod tests { ]; for t in &cases { - assert!(check_pack_u64s(&t)); + assert!(check_pack_u64s(t)); } } diff --git a/src/pdata/array_walker.rs b/src/pdata/array_walker.rs index aa314e9..843ba1c 100644 --- a/src/pdata/array_walker.rs +++ b/src/pdata/array_walker.rs @@ -77,7 +77,7 @@ impl<'a, V: Unpack + Copy> NodeVisitor for BlockValueVisitor<'a, V> { for (i, b) in values.iter().enumerate() { // TODO: report indices of array entries based on the type size let mut array_errs = self.array_errs.lock().unwrap(); - array_errs.push(array::io_err(&path, *b).index_context(keys[i])); + array_errs.push(array::io_err(path, *b).index_context(keys[i])); } } Ok(rblocks) => { @@ -85,7 +85,7 @@ impl<'a, V: Unpack + Copy> NodeVisitor for BlockValueVisitor<'a, V> { match rb { Err(_) => { let mut array_errs = self.array_errs.lock().unwrap(); - array_errs.push(array::io_err(&path, values[i]).index_context(keys[i])); + array_errs.push(array::io_err(path, values[i]).index_context(keys[i])); } Ok(b) => { let mut path = path.to_vec(); diff --git a/src/pdata/btree.rs b/src/pdata/btree.rs index 14105a9..10883d7 100644 --- a/src/pdata/btree.rs +++ b/src/pdata/btree.rs @@ -561,7 +561,7 @@ pub fn unpack_node( if let Some(l) = last { if k <= l { return Err(node_err( - &path, + path, &format!("keys out of order: {} <= {}", k, l), )); } @@ -582,7 +582,7 @@ pub fn unpack_node( values, }) } else { - let (_i, values) = convert_result(&path, count(le_u64, header.nr_entries as usize)(i))?; + let (_i, values) = convert_result(path, count(le_u64, header.nr_entries as usize)(i))?; Ok(Node::Internal { header, keys, diff --git a/src/pdata/btree_leaf_walker.rs b/src/pdata/btree_leaf_walker.rs index b19da99..3da1de3 100644 --- a/src/pdata/btree_leaf_walker.rs +++ b/src/pdata/btree_leaf_walker.rs @@ -132,10 +132,10 @@ impl<'a> LeafWalker<'a> { .keys_context(kr)); } - let node = unpack_node::(path, &b.get_data(), self.ignore_non_fatal, is_root)?; + let node = unpack_node::(path, b.get_data(), self.ignore_non_fatal, is_root)?; if let Internal { keys, values, .. } = node { - let krs = split_key_ranges(path, &kr, &keys)?; + let krs = split_key_ranges(path, kr, &keys)?; if depth == 0 { // it is the lowest internal for i in 0..krs.len() { @@ -187,7 +187,7 @@ impl<'a> LeafWalker<'a> { )); } - let node = unpack_node::(path, &b.get_data(), self.ignore_non_fatal, is_root)?; + let node = unpack_node::(path, b.get_data(), self.ignore_non_fatal, is_root)?; match node { Internal { values, .. } => { diff --git a/src/pdata/btree_walker.rs b/src/pdata/btree_walker.rs index b6dd6b7..b25f204 100644 --- a/src/pdata/btree_walker.rs +++ b/src/pdata/btree_walker.rs @@ -195,11 +195,11 @@ impl BTreeWalker { .keys_context(kr)); } - let node = unpack_node::(path, &b.get_data(), self.ignore_non_fatal, is_root)?; + let node = unpack_node::(path, b.get_data(), self.ignore_non_fatal, is_root)?; match node { Internal { keys, values, .. } => { - let krs = split_key_ranges(path, &kr, &keys)?; + let krs = split_key_ranges(path, kr, &keys)?; let errs = self.walk_nodes(path, visitor, &krs, &values); return self.build_aggregate(b.loc, errs); } @@ -208,7 +208,7 @@ impl BTreeWalker { keys, values, } => { - if let Err(e) = visitor.visit(path, &kr, &header, &keys, &values) { + if let Err(e) = visitor.visit(path, kr, &header, &keys, &values) { let e = BTreeError::Path(path.clone(), Box::new(e)); self.set_fail(b.loc, e.clone()); return Err(e); @@ -286,11 +286,11 @@ where .keys_context(kr)); } - let node = unpack_node::(path, &b.get_data(), w.ignore_non_fatal, is_root)?; + let node = unpack_node::(path, b.get_data(), w.ignore_non_fatal, is_root)?; match node { Internal { keys, values, .. } => { - let krs = split_key_ranges(path, &kr, &keys)?; + let krs = split_key_ranges(path, kr, &keys)?; let errs = walk_nodes_threaded(w.clone(), path, pool, visitor, &krs, &values); return w.build_aggregate(b.loc, errs); } diff --git a/src/pdata/space_map_checker.rs b/src/pdata/space_map_checker.rs index ad5998b..4f284bf 100644 --- a/src/pdata/space_map_checker.rs +++ b/src/pdata/space_map_checker.rs @@ -109,7 +109,7 @@ fn check_low_ref_counts( return Err(anyhow!("Unable to read bitmap block")); } Ok(b) => { - if checksum::metadata_block_type(&b.get_data()) != checksum::BT::BITMAP { + if checksum::metadata_block_type(b.get_data()) != checksum::BT::BITMAP { report.fatal(&format!( "Index entry points to block ({}) that isn't a bitmap", b.loc diff --git a/src/report.rs b/src/report.rs index 8b0fb3e..37058c8 100644 --- a/src/report.rs +++ b/src/report.rs @@ -117,7 +117,7 @@ impl ReportInner for PBInner { fn set_sub_title(&mut self, txt: &str) { //let mut fmt = "".to_string(); //Checking thin metadata".to_string(); //self.title.clone(); let mut fmt = "Checking thin metadata [{bar:40}] Remaining {eta}, ".to_string(); - fmt.push_str(&txt); + fmt.push_str(txt); self.bar.set_style( ProgressStyle::default_bar() .template(&fmt) diff --git a/src/shrink/toplevel.rs b/src/shrink/toplevel.rs index fb47773..65ffcc5 100644 --- a/src/shrink/toplevel.rs +++ b/src/shrink/toplevel.rs @@ -343,16 +343,16 @@ fn find_first(r: &BlockRange, remaps: &[(BlockRange, BlockRange)]) -> Option { if n == 0 { let (from, _) = &remaps[n]; - overlaps(&r, &from, n) + overlaps(r, from, n) } else if n == remaps.len() { let (from, _) = &remaps[n - 1]; - overlaps(&r, from, n - 1) + overlaps(r, from, n - 1) } else { // Need to check the previous entry let (from, _) = &remaps[n - 1]; - overlaps(&r, &from, n - 1).or_else(|| { + overlaps(r, from, n - 1).or_else(|| { let (from, _) = &remaps[n]; - overlaps(&r, &from, n) + overlaps(r, from, n) }) } } @@ -368,7 +368,7 @@ fn remap(r: &BlockRange, remaps: &[(BlockRange, BlockRange)]) -> Vec let mut remap = Vec::new(); let mut r = r.start..r.end; - if let Some(index) = find_first(&r, &remaps) { + if let Some(index) = find_first(&r, remaps) { let mut index = index; loop { let (from, to) = &remaps[index]; @@ -487,7 +487,7 @@ fn build_copy_regions(remaps: &[(BlockRange, BlockRange)], block_size: u64) -> V rs.push(Region { src: from.start * block_size, dest: to.start * block_size, - len: range_len(&from) * block_size, + len: range_len(from) * block_size, }); } diff --git a/src/thin/dump.rs b/src/thin/dump.rs index 28e21bf..75003dd 100644 --- a/src/thin/dump.rs +++ b/src/thin/dump.rs @@ -188,7 +188,7 @@ fn emit_leaf(v: &mut MappingVisitor, b: &Block) -> Result<()> { ))); } - let node = unpack_node::(&path, &b.get_data(), true, true)?; + let node = unpack_node::(&path, b.get_data(), true, true)?; match node { Internal { .. } => { diff --git a/src/thin/restore.rs b/src/thin/restore.rs index ecaa7a0..9ad7b19 100644 --- a/src/thin/restore.rs +++ b/src/thin/restore.rs @@ -153,7 +153,7 @@ impl<'a> Restorer<'a> { }; for (_, leaves) in self.sub_trees.iter() { - release_leaves(self.w, &leaves, &mut value_rc)?; + release_leaves(self.w, leaves, &mut value_rc)?; } Ok(()) diff --git a/src/thin/runs.rs b/src/thin/runs.rs index be8e287..be929ec 100644 --- a/src/thin/runs.rs +++ b/src/thin/runs.rs @@ -125,7 +125,7 @@ impl Gatherer { // Now we need to mark entries that follow a tail as heads. let mut heads = mem::take(&mut self.heads); for t in &self.tails { - if let Some(e) = self.entries.get(&t) { + if let Some(e) = self.entries.get(t) { for n in &e.neighbours { heads.insert(*n); } diff --git a/tests/cache_check.rs b/tests/cache_check.rs index b3e9c9a..d778cca 100644 --- a/tests/cache_check.rs +++ b/tests/cache_check.rs @@ -13,8 +13,7 @@ use common::test_dir::*; //------------------------------------------ -const USAGE: &str = -"cache_check 0.9.0 +const USAGE: &str = "cache_check 0.9.0 USAGE: cache_check [FLAGS] @@ -105,7 +104,10 @@ fn failing_q() -> Result<()> { let md = mk_zeroed_md(&mut td)?; let output = run_fail_raw(cache_check_cmd(args!["-q", &md]))?; assert_eq!(output.stdout.len(), 0); - eprintln!("stderr = '{}'", std::str::from_utf8(&output.stderr).unwrap()); + eprintln!( + "stderr = '{}'", + std::str::from_utf8(&output.stderr).unwrap() + ); assert_eq!(output.stderr.len(), 0); Ok(()) } @@ -128,7 +130,6 @@ fn valid_metadata_passes() -> Result<()> { Ok(()) } - // FIXME: put back in, I don't want to add the --debug- arg to the // tool again, so we should have a little library function for tweaking // metadata version. diff --git a/tests/cache_repair.rs b/tests/cache_repair.rs index 524b376..8a0bb39 100644 --- a/tests/cache_repair.rs +++ b/tests/cache_repair.rs @@ -12,8 +12,7 @@ use common::test_dir::*; //------------------------------------------ -const USAGE: &str = -"cache_repair 0.9.0 +const USAGE: &str = "cache_repair 0.9.0 Repair binary cache metadata, and write it to a different device or file USAGE: diff --git a/tests/cache_restore.rs b/tests/cache_restore.rs index aebc6d1..c6b80aa 100644 --- a/tests/cache_restore.rs +++ b/tests/cache_restore.rs @@ -14,8 +14,7 @@ use common::test_dir::*; //------------------------------------------ -const USAGE: &str = -"cache_restore 0.9.0 +const USAGE: &str = "cache_restore 0.9.0 Convert XML format metadata to binary. USAGE: diff --git a/tests/common/cache_xml_generator.rs b/tests/common/cache_xml_generator.rs index 27c9c6f..1719192 100644 --- a/tests/common/cache_xml_generator.rs +++ b/tests/common/cache_xml_generator.rs @@ -64,7 +64,7 @@ impl XmlGen for CacheGen { let mut cblocks = (0..self.nr_cache_blocks).collect::>(); cblocks.shuffle(&mut rand::thread_rng()); cblocks.truncate(nr_resident as usize); - cblocks.sort(); + cblocks.sort_unstable(); v.mappings_b()?; { diff --git a/tests/common/input_arg.rs b/tests/common/input_arg.rs index 87b1673..2dfae10 100644 --- a/tests/common/input_arg.rs +++ b/tests/common/input_arg.rs @@ -222,9 +222,8 @@ where let wrapper = build_args_fn(P::arg_type())?; wrapper(&mut td, input.as_ref(), &|args: &[&OsStr]| { let stderr = run_fail(P::cmd(args))?; - let msg = format!( - "This looks like XML. This tool only checks the binary metadata format.", - ); + let msg = + "This looks like XML. This tool only checks the binary metadata format.".to_string(); assert!(stderr.contains(&msg)); Ok(()) }) diff --git a/tests/common/process.rs b/tests/common/process.rs index 7f6fed6..790b9ef 100644 --- a/tests/common/process.rs +++ b/tests/common/process.rs @@ -57,10 +57,10 @@ impl fmt::Display for Command { fn log_output(output: &process::Output) { use std::str::from_utf8; - if output.stdout.len() > 0 { + if !output.stdout.is_empty() { eprintln!("stdout: \n{}<>", from_utf8(&output.stdout).unwrap()); } - if output.stderr.len() > 0 { + if !output.stderr.is_empty() { eprintln!("stderr: \n{}<>", from_utf8(&output.stderr).unwrap()); } } diff --git a/tests/common/thin.rs b/tests/common/thin.rs index a66ece7..a86a096 100644 --- a/tests/common/thin.rs +++ b/tests/common/thin.rs @@ -118,7 +118,7 @@ pub fn generate_metadata_leaks( pub fn get_needs_check(md: &PathBuf) -> Result { use thinp::thin::superblock::*; - let engine = SyncIoEngine::new(&md, 1, false)?; + let engine = SyncIoEngine::new(md, 1, false)?; let sb = read_superblock(&engine, SUPERBLOCK_LOCATION)?; Ok(sb.flags.needs_check) } diff --git a/tests/thin_check.rs b/tests/thin_check.rs index e22d2b4..14d1c7a 100644 --- a/tests/thin_check.rs +++ b/tests/thin_check.rs @@ -145,11 +145,11 @@ fn accepts_quiet() -> Result<()> { let md = mk_valid_md(&mut td)?; let output = run_ok_raw(thin_check_cmd(args!["--quiet", &md]))?; - if output.stdout.len() > 0 { + if !output.stdout.is_empty() { eprintln!("stdout: {:?}", &std::str::from_utf8(&output.stdout)); } - if output.stderr.len() > 0 { + if !output.stderr.is_empty() { eprintln!("stderr: {:?}", &std::str::from_utf8(&output.stderr)); } assert_eq!(output.stdout.len(), 0); diff --git a/tests/thin_dump.rs b/tests/thin_dump.rs index 254c41f..821b96f 100644 --- a/tests/thin_dump.rs +++ b/tests/thin_dump.rs @@ -15,8 +15,7 @@ use common::thin::*; //------------------------------------------ -const USAGE: &str = -"thin_dump 0.9.0 +const USAGE: &str = "thin_dump 0.9.0 Dump thin-provisioning metadata to stdout in XML format USAGE: @@ -178,15 +177,13 @@ fn repair_superblock() -> Result<()> { let before = run_ok_raw(thin_dump_cmd(args![&md]))?; damage_superblock(&md)?; - let after = run_ok_raw(thin_dump_cmd( - args![ - "--repair", - "--transaction-id=1", - "--data-block-size=128", - "--nr-data-blocks=20480", - &md - ], - ))?; + let after = run_ok_raw(thin_dump_cmd(args![ + "--repair", + "--transaction-id=1", + "--data-block-size=128", + "--nr-data-blocks=20480", + &md + ]))?; if !cfg!(feature = "rust_tests") { assert_eq!(after.stderr.len(), 0); } @@ -204,15 +201,12 @@ fn missing_transaction_id() -> Result<()> { let mut td = TestDir::new()?; let md = mk_valid_md(&mut td)?; damage_superblock(&md)?; - let stderr = run_fail( - thin_dump_cmd( - args![ - "--repair", - "--data-block-size=128", - "--nr-data-blocks=20480", - &md - ], - ))?; + let stderr = run_fail(thin_dump_cmd(args![ + "--repair", + "--data-block-size=128", + "--nr-data-blocks=20480", + &md + ]))?; assert!(stderr.contains("transaction id")); Ok(()) } @@ -222,15 +216,12 @@ fn missing_data_block_size() -> Result<()> { let mut td = TestDir::new()?; let md = mk_valid_md(&mut td)?; damage_superblock(&md)?; - let stderr = run_fail( - thin_dump_cmd( - args![ - "--repair", - "--transaction-id=1", - "--nr-data-blocks=20480", - &md - ], - ))?; + let stderr = run_fail(thin_dump_cmd(args![ + "--repair", + "--transaction-id=1", + "--nr-data-blocks=20480", + &md + ]))?; assert!(stderr.contains("data block size")); Ok(()) } @@ -240,15 +231,12 @@ fn missing_nr_data_blocks() -> Result<()> { let mut td = TestDir::new()?; let md = mk_valid_md(&mut td)?; damage_superblock(&md)?; - let stderr = run_fail( - thin_dump_cmd( - args![ - "--repair", - "--transaction-id=1", - "--data-block-size=128", - &md - ], - ))?; + let stderr = run_fail(thin_dump_cmd(args![ + "--repair", + "--transaction-id=1", + "--data-block-size=128", + &md + ]))?; assert!(stderr.contains("nr data blocks")); Ok(()) } diff --git a/tests/thin_metadata_unpack.rs b/tests/thin_metadata_unpack.rs index 2e5d6c3..89b660a 100644 --- a/tests/thin_metadata_unpack.rs +++ b/tests/thin_metadata_unpack.rs @@ -106,8 +106,18 @@ fn end_to_end() -> Result<()> { let mut td = TestDir::new()?; let md_in = mk_valid_md(&mut td)?; let md_out = mk_zeroed_md(&mut td)?; - run_ok(thin_metadata_pack_cmd(args!["-i", &md_in, "-o", "meta.pack"]))?; - run_ok(thin_metadata_unpack_cmd(args!["-i", "meta.pack", "-o", &md_out]))?; + run_ok(thin_metadata_pack_cmd(args![ + "-i", + &md_in, + "-o", + "meta.pack" + ]))?; + run_ok(thin_metadata_unpack_cmd(args![ + "-i", + "meta.pack", + "-o", + &md_out + ]))?; let dump1 = run_ok(thin_dump_cmd(args![&md_in]))?; let dump2 = run_ok(thin_dump_cmd(args![&md_out]))?; diff --git a/tests/thin_repair.rs b/tests/thin_repair.rs index f8264e2..244e4be 100644 --- a/tests/thin_repair.rs +++ b/tests/thin_repair.rs @@ -161,18 +161,15 @@ fn superblock_succeeds() -> Result<()> { } damage_superblock(&md1)?; let md2 = mk_zeroed_md(&mut td)?; - run_ok( - thin_repair_cmd( - args![ - "--transaction-id=1", - "--data-block-size=128", - "--nr-data-blocks=20480", - "-i", - &md1, - "-o", - &md2 - ], - ))?; + run_ok(thin_repair_cmd(args![ + "--transaction-id=1", + "--data-block-size=128", + "--nr-data-blocks=20480", + "-i", + &md1, + "-o", + &md2 + ]))?; let repaired = run_ok_raw(thin_dump_cmd(args![&md2]))?; if !cfg!(feature = "rust_tests") { assert_eq!(repaired.stderr.len(), 0);