Skip to content

Commit

Permalink
Fix some issues discovered while making tests
Browse files Browse the repository at this point in the history
Fix check mode not reading inline data.
Fix length option being improperly parsed.
Bail out on wrong option.
  • Loading branch information
HacKanCuBa committed Apr 26, 2017
1 parent f1192d1 commit 7cff0c1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/b2rsum.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
# Changelog
#=====================
#
# v0.1.1
# - Fix check mode not reading inline data
# - Fix length option being improperly parsed
# - Bail out on wrong option
#
# v0.1.0
# - First release
#
Expand All @@ -43,7 +48,7 @@
#------------------------------------------------------------------------

# Config
declare -r VERSION="0.1.0"
declare -r VERSION="0.1.1"
declare -r OUTPUT_FILENAME_DEFAULT="BLAKE2SUMS"
declare -r QUIET_DEFAULT=false
#--------------------------#
Expand Down Expand Up @@ -199,7 +204,7 @@ cmd_create() {

if [[ "$item" == "-" ]]; then
# shellcheck disable=SC2016
EXEC='cat - | b2sum $([[ ${#B2SUM_OPTS[*]} -ge 1 ]] && printf "%s" "${B2SUM_OPTS[*]}")'
EXEC='cat - | b2sum $([[ ${#B2SUM_OPTS[*]} -ge 1 ]] && printf "%s" "${B2SUM_OPTS[*]}") -'
elif [[ -e "$item" ]]; then
# shellcheck disable=SC2016
EXEC='find -L "$item" -type f ! -name "$OUTPUT_FILE" -print0 | xargs -0 b2sum $([[ ${#B2SUM_OPTS[*]} -ge 1 ]] && printf "%s" "${B2SUM_OPTS[*]}")'
Expand Down Expand Up @@ -231,7 +236,10 @@ cmd_check() {
for hashfile in "${HASHFILES[@]}"; do
check_sneaky_paths "$hashfile"

if [[ -r "$hashfile" ]]; then
if [[ "$hashfile" == "-" ]]; then
# shellcheck disable=SC2016
EXEC='cat - | b2sum --check $([[ ${#B2SUM_OPTS[*]} -ge 1 ]] && printf "%s" "${B2SUM_OPTS[*]}") $([[ ${#B2SUM_OPTS_CHECK[*]} -ge 1 ]] && printf "%s" "${B2SUM_OPTS_CHECK[*]}") -'
elif [[ -r "$hashfile" ]]; then
# shellcheck disable=SC2016
EXEC='b2sum --check $([[ ${#B2SUM_OPTS[*]} -ge 1 ]] && printf "%s" "${B2SUM_OPTS[*]}") $([[ ${#B2SUM_OPTS_CHECK[*]} -ge 1 ]] && printf "%s" "${B2SUM_OPTS_CHECK[*]}") "$hashfile"'
else
Expand Down Expand Up @@ -265,15 +273,17 @@ declare OUTPUT_FILE=''
check_dependencies || die "Dependencies not met, can't continue"

# Arguments
OPTS="$(getopt -o hbcltwosq -l help,version,license,binary,check,length,text,tag,ignore-missing,quiet,status,strict,warn,output -n "$PROGRAM" -- "$@")"
OPTS="$(getopt -o hbctwosql: -l help,version,license,binary,check,length:,text,tag,ignore-missing,quiet,status,strict,warn,output -n "$PROGRAM" -- "$@")"
[[ $? -ne 0 ]] && die "Wrong option. Try '$PROGRAM --help' for more information."

eval set -- "$OPTS"
while true; do case $1 in
-h|--help) cmd_help; exit $EXIT_SUCCESS;;
--version) cmd_version; exit $EXIT_SUCCESS;;
--license) cmd_license; exit $EXIT_SUCCESS;;
-b|--binary) B2SUM_OPTS+=( '--binary' ); shift;;
-c|--check) MODE_CHECK=true; shift;;
-l|--length) B2SUM_OPTS+=( '--length' ); shift;;
-l|--length) B2SUM_OPTS+=( '--length' "$2" ); shift 2;;
--tag) B2SUM_OPTS+=( '--tag' ); shift;;
-t|--text) B2SUM_OPTS+=( '--text' ); shift;;
--ignore-missing) B2SUM_OPTS_CHECK+=( '--ignore-missing' ); shift;;
Expand Down

0 comments on commit 7cff0c1

Please sign in to comment.