Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #110 from darrenldl/dev
Browse files Browse the repository at this point in the history
Added --only-pick-uid to show mode, replaced uid with UID in output text
  • Loading branch information
darrenldl committed Dec 25, 2018
2 parents 170d38f + 55a1a6c commit 5e5a90d
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 18 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## 2.2.0

- Added `--only-pick-uid` option to show mode

- Changed "uid" to "UID" in output text for consistency

## 2.1.0

- Added `--burst` flag to decode mode, used when output is stdout and container version is RS enabled
- Added `--burst` option to decode mode, used when output is stdout and container version is RS enabled

- Updated help messages in decode, encode mode to note that `./-` can be used when the file of interest is named `-`

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blkar"
version = "2.1.0"
version = "2.2.0"
authors = ["Darren Ldl <darrenldldev@gmail.com>"]
build = "build.rs"
exclude = [
Expand Down
2 changes: 1 addition & 1 deletion src/cli_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This means this option has no effect for version 17, 18, 19."))
.value_name("UID-HEX")
.long("uid")
.takes_value(true)
.help("Alternative file uid in hex (by default uid is randomly generated).
.help("Alternative file UID in hex (by default UID is randomly generated).
Uid must be exactly 6 bytes (12 hex digits) in length."))
.arg(rs_data_arg())
.arg(rs_parity_arg())
Expand Down
14 changes: 14 additions & 0 deletions src/cli_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ macro_rules! parse_uid {
) => {{
use misc_utils::HexError;
use misc_utils;
use sbx_specs::SBX_FILE_UID_LEN;

match misc_utils::hex_string_to_bytes($uid) {
Ok(x) => {
if x.len() != SBX_FILE_UID_LEN {
Expand All @@ -294,6 +296,18 @@ macro_rules! parse_uid {
}}
}

macro_rules! get_uid {
(
$matches:expr, $buf:expr, $json_printer:expr
) => {{
match $matches.value_of("uid") {
None => None ,
Some(uid) => { parse_uid!($buf, uid, $json_printer);
Some(&$buf) }
}
}}
}

macro_rules! get_ref_block_choice {
(
$matches:expr
Expand Down
15 changes: 2 additions & 13 deletions src/cli_rescue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ range specified in the initial run."))
any
meta
data"))
.arg(Arg::with_name("uid")
.value_name("UID-HEX")
.long("only-pick-uid")
.takes_value(true)
.help("Only pick blocks with UID-HEX as uid. Uid must be exactly 6
bytes (12 hex digits) in length."))
.arg(only_pick_uid_arg())
.arg(force_misalign_arg())
.arg(pr_verbosity_level_arg())
.arg(from_byte_arg()
Expand All @@ -59,13 +54,7 @@ pub fn rescue<'a>(matches : &ArgMatches<'a>) -> i32 {
json_printer.print_open_bracket(None, BracketType::Curly);

let mut temp_uid = [0; SBX_FILE_UID_LEN];
let uid : Option<&[u8; SBX_FILE_UID_LEN]> = {
match matches.value_of("uid") {
None => None ,
Some(x) => { parse_uid!(temp_uid, x, json_printer);
Some(&temp_uid) }
}
};
let uid : Option<&[u8; SBX_FILE_UID_LEN]> = get_uid!(matches, temp_uid, json_printer);

let block_type = match matches.value_of("block_type") {
None => None,
Expand Down
6 changes: 6 additions & 0 deletions src/cli_show.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use show_core::Param;
use show_core;
use sbx_specs::SBX_FILE_UID_LEN;
use std::str::FromStr;

use json_printer::BracketType;
Expand All @@ -15,6 +16,7 @@ pub fn sub_command<'a, 'b>() -> App<'a, 'b> {
.arg(Arg::with_name("show_all")
.long("show-all")
.help("Show all metadata (by default only shows the first one)"))
.arg(only_pick_uid_arg())
.arg(force_misalign_arg())
.arg(pr_verbosity_level_arg())
.arg(from_byte_arg()
Expand All @@ -41,13 +43,17 @@ pub fn show<'a>(matches : &ArgMatches<'a>) -> i32 {
let from_pos = get_from_pos!(matches, json_printer);
let to_pos = get_to_pos!(matches, json_printer);

let mut temp_uid = [0; SBX_FILE_UID_LEN];
let uid : Option<&[u8; SBX_FILE_UID_LEN]> = get_uid!(matches, temp_uid, json_printer);

let param = Param::new(matches.is_present("show_all"),
matches.is_present("guess_burst"),
matches.is_present("force_misalign"),
&json_printer,
from_pos,
to_pos,
in_file,
uid,
pr_verbosity_level);
match show_core::show_file(&param) {
Ok(s) => exit_with_msg!(ok json_printer => "{}", s),
Expand Down
9 changes: 9 additions & 0 deletions src/cli_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ pub fn force_misalign_arg<'a, 'b>() -> Arg<'a, 'b> {
used and is only intended for data recovery or related purposes.")
}

pub fn only_pick_uid_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("uid")
.value_name("UID-HEX")
.long("only-pick-uid")
.takes_value(true)
.help("Only pick blocks with UID-HEX as UID. UID must be exactly 6
bytes (12 hex digits) in length.")
}

pub fn from_byte_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("from_pos")
.value_name("FROM-BYTE")
Expand Down
2 changes: 1 addition & 1 deletion src/rescue_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub fn rescue_from_file(param : &Param)
if block.block_type() != x { continue; }
}

// check if block has the required uid
// check if block has the required UID
if let Some(x) = param.only_pick_uid {
if block.get_uid() != x { continue; }
}
Expand Down
13 changes: 13 additions & 0 deletions src/show_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use json_printer::BracketType;

use progress_report::*;

use sbx_specs::SBX_FILE_UID_LEN;

use file_reader::{FileReader,
FileReaderParam};

Expand Down Expand Up @@ -86,6 +88,7 @@ pub struct Param {
from_pos : Option<u64>,
to_pos : Option<u64>,
in_file : String,
only_pick_uid : Option<[u8; SBX_FILE_UID_LEN]>,
pr_verbosity_level : PRVerbosityLevel
}

Expand All @@ -97,6 +100,7 @@ impl Param {
from_pos : Option<u64>,
to_pos : Option<u64>,
in_file : &str,
only_pick_uid : Option<&[u8; SBX_FILE_UID_LEN]>,
pr_verbosity_level : PRVerbosityLevel) -> Param {
Param {
show_all,
Expand All @@ -106,6 +110,10 @@ impl Param {
from_pos,
to_pos,
in_file : String::from(in_file),
only_pick_uid : match only_pick_uid {
None => None,
Some(x) => Some(x.clone())
},
pr_verbosity_level,
}
}
Expand Down Expand Up @@ -212,6 +220,11 @@ pub fn show_file(param : &Param)
if !lazy_read_res.usable { continue; }

if block.is_meta() {
// check if block has the required UID
if let Some(x) = param.only_pick_uid {
if block.get_uid() != x { continue; }
}

reporter.pause();

json_printer.print_open_bracket(None, BracketType::Curly);
Expand Down
18 changes: 18 additions & 0 deletions tests/dev_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ if [[ $? != 0 ]]; then
test_failed_names=$test_failed_names"- rescue_pick_uid_tests_decode_stdout.sh\n"
fi

echo "========================================"
echo "Starting show with specified range tests"
echo "========================================"
./show_from_to_tests.sh
if [[ $? != 0 ]]; then
test_failed=$[$test_failed+1]
test_failed_names=$test_failed_names"- show_from_to_tests.sh\n"
fi

echo "========================================"
echo "Starting show with specified uid tests"
echo "========================================"
./show_pick_uid_tests.sh
if [[ $? != 0 ]]; then
test_failed=$[$test_failed+1]
test_failed_names=$test_failed_names"- show_pick_uid_tests.sh\n"
fi

# output file tests
echo "========================================"
echo "Starting output file path logic tests"
Expand Down
97 changes: 97 additions & 0 deletions tests/show_from_to_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

exit_code=0

echo "Creating empty files"
touch dummy_empty1
touch dummy_empty2

echo -n "Encoding 1st file"
output=$(./blkar encode --json -f dummy_empty1 --uid DEADBEEF0001)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.fileUID") == "DEADBEEF0001" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo -n "Encoding 2nd file"
output=$(./blkar encode --json -f dummy_empty2 --uid DEADBEEF0002)
if [[ $(echo $output | jq -r ".error") != null ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".stats.fileUID") == "DEADBEEF0002" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo "Crafting dummy disk file"
rm dummy_empty_disk &>/dev/null
cat dummy_empty1.sbx >> dummy_empty_disk
cat dummy_empty2.sbx >> dummy_empty_disk

echo -n "Checking that blkar only shows first block"
output=$(./blkar show --json --show-all dummy_empty_disk --from 0 --to 511)
if [[ $(echo $output | jq -r ".error") != "null" ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".blocks[0].fileUID") == "DEADBEEF0001" ]]; then
echo -n " ==> Okay"
else
echo -n " ==> NOT okay"
exit_code=1
fi
if [[ $(echo $output | jq -r ".blocks[1]") == "null" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo -n "Checking that blkar only shows second block"
output=$(./blkar show --json --show-all dummy_empty_disk --from 512 --to 512)
if [[ $(echo $output | jq -r ".error") != "null" ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".blocks[0].fileUID") == "DEADBEEF0002" ]]; then
echo -n " ==> Okay"
else
echo -n " ==> NOT okay"
exit_code=1
fi
if [[ $(echo $output | jq -r ".blocks[1]") == "null" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

echo -n "Checking that blkar shows both blocks"
output=$(./blkar show --json --show-all dummy_empty_disk)
if [[ $(echo $output | jq -r ".error") != "null" ]]; then
echo " ==> Invalid JSON"
exit_code=1
fi
if [[ $(echo $output | jq -r ".blocks[0].fileUID") == "DEADBEEF0001" ]]; then
echo -n " ==> Okay"
else
echo -n " ==> NOT okay"
exit_code=1
fi
if [[ $(echo $output | jq -r ".blocks[1].fileUID") == "DEADBEEF0002" ]]; then
echo " ==> Okay"
else
echo " ==> NOT okay"
exit_code=1
fi

exit $exit_code

0 comments on commit 5e5a90d

Please sign in to comment.