2020-08-05 14:30:44 +05:30
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
mod common;
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
use common::common_args::*;
|
2021-07-20 15:07:55 +05:30
|
|
|
use common::fixture::*;
|
2021-07-01 19:57:37 +05:30
|
|
|
use common::input_arg::*;
|
|
|
|
use common::output_option::*;
|
2021-07-20 15:07:55 +05:30
|
|
|
use common::process::*;
|
|
|
|
use common::program::*;
|
|
|
|
use common::target::*;
|
2020-08-07 19:00:00 +05:30
|
|
|
use common::test_dir::*;
|
2021-07-20 15:07:55 +05:30
|
|
|
use common::thin::*;
|
2020-08-05 14:30:44 +05:30
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
const USAGE: &str = concat!(
|
|
|
|
"thin_metadata_unpack ",
|
|
|
|
include_str!("../VERSION"),
|
|
|
|
"Unpack a compressed file of thin metadata.\n\
|
|
|
|
\n\
|
|
|
|
USAGE:\n \
|
|
|
|
thin_metadata_unpack -i <DEV> -o <FILE>\n\
|
|
|
|
\n\
|
|
|
|
FLAGS:\n \
|
|
|
|
-h, --help Prints help information\n \
|
|
|
|
-V, --version Prints version information\n\
|
|
|
|
\n\
|
|
|
|
OPTIONS:\n \
|
|
|
|
-i <DEV> Specify thinp metadata binary device/file\n \
|
|
|
|
-o <FILE> Specify packed output file"
|
|
|
|
);
|
2020-08-05 14:30:44 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
//------------------------------------------
|
2020-08-05 14:30:44 +05:30
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
struct ThinMetadataUnpack;
|
2020-08-05 14:30:44 +05:30
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
impl<'a> Program<'a> for ThinMetadataUnpack {
|
|
|
|
fn name() -> &'a str {
|
|
|
|
"thin_metadata_pack"
|
|
|
|
}
|
2020-08-05 14:30:44 +05:30
|
|
|
|
2021-10-18 21:29:17 +05:30
|
|
|
fn cmd<I>(args: I) -> Command
|
2021-10-11 16:37:26 +05:30
|
|
|
where
|
|
|
|
I: IntoIterator,
|
|
|
|
I::Item: Into<std::ffi::OsString>,
|
|
|
|
{
|
|
|
|
thin_metadata_unpack_cmd(args)
|
2021-07-06 07:21:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
fn usage() -> &'a str {
|
|
|
|
USAGE
|
|
|
|
}
|
|
|
|
|
|
|
|
fn arg_type() -> ArgType {
|
|
|
|
ArgType::IoOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bad_option_hint(option: &str) -> String {
|
2021-10-11 16:37:26 +05:30
|
|
|
msg::bad_option_hint(option)
|
2021-07-06 07:21:27 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> InputProgram<'a> for ThinMetadataUnpack {
|
|
|
|
fn mk_valid_input(td: &mut TestDir) -> Result<std::path::PathBuf> {
|
|
|
|
mk_zeroed_md(td) // FIXME: make a real pack file
|
|
|
|
}
|
|
|
|
|
|
|
|
fn file_not_found() -> &'a str {
|
2021-10-11 16:37:26 +05:30
|
|
|
msg::FILE_NOT_FOUND
|
2021-07-06 07:21:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
fn missing_input_arg() -> &'a str {
|
2021-10-11 16:37:26 +05:30
|
|
|
msg::MISSING_INPUT_ARG
|
2021-07-06 07:21:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
fn corrupted_input() -> &'a str {
|
|
|
|
"Not a pack file"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> OutputProgram<'a> for ThinMetadataUnpack {
|
|
|
|
fn missing_output_arg() -> &'a str {
|
2021-10-11 16:37:26 +05:30
|
|
|
msg::MISSING_OUTPUT_ARG
|
2021-07-06 07:21:27 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
|
|
|
test_accepts_help!(ThinMetadataUnpack);
|
|
|
|
test_accepts_version!(ThinMetadataUnpack);
|
|
|
|
test_rejects_bad_option!(ThinMetadataUnpack);
|
|
|
|
|
|
|
|
test_missing_input_option!(ThinMetadataUnpack);
|
|
|
|
test_input_file_not_found!(ThinMetadataUnpack);
|
|
|
|
test_corrupted_input_data!(ThinMetadataUnpack);
|
|
|
|
|
|
|
|
test_missing_output_option!(ThinMetadataUnpack);
|
2020-08-05 14:30:44 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
//------------------------------------------
|
2020-08-05 14:30:44 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
// TODO: share with thin_restore/cache_restore/era_restore
|
2020-08-05 14:30:44 +05:30
|
|
|
|
|
|
|
#[test]
|
|
|
|
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)?;
|
2021-10-11 16:37:26 +05:30
|
|
|
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]))?;
|
2020-08-05 14:30:44 +05:30
|
|
|
assert_eq!(dump1, dump2);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|