Commit d4389749 authored by pcw109550's avatar pcw109550

op-chain-ops: Apply Delta checker bash script suggestions

parent 406c2ca9
#!/bin/bash #!/bin/bash
set -uo pipefail
# Check if a directory path is provided # Check if a directory path is provided
# Directory must contain the output of batch_decoder's reassemble command # Directory must contain the output of batch_decoder's reassemble command
if [ -z "$1" ]; then if [ -z "${1:-}" ]; then
echo "Usage: $0 /path/to/directory" echo "Usage: $0 /path/to/directory"
exit 1 exit 1
fi fi
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed"
exit 1
fi
directory_path=$1 directory_path=$1
# Check if directory exists and is not empty
if [ ! -d "$directory_path" ] || [ -z "$(ls -A "$directory_path")" ]; then
echo "Error: Directory does not exist or is empty"
exit 1
fi
valid_count=0 valid_count=0
invalid_count=0 invalid_count=0
invalid_channels=() invalid_channels=()
...@@ -16,10 +28,11 @@ invalid_channels=() ...@@ -16,10 +28,11 @@ invalid_channels=()
for file in "$directory_path"/*.json; do for file in "$directory_path"/*.json; do
# If channel is ready, all batches must valid. # If channel is ready, all batches must valid.
# If delta is activated, all batch types must be span batch. # If delta is activated, all batch types must be span batch.
result=$(jq 'if .is_ready then (.invalid_batches == false and all(.batch_types[]; . == 1)) else empty end' "$file") result=$(jq 'if .is_ready then (.invalid_batches == false and all(.batch_types[]; . == 1)) else empty end' "$file" 2>&1)
if [[ $result == "true" ]]; then if [[ $result == "true" ]]; then
((valid_count++)) ((valid_count++))
elif [[ $result == "false" ]]; then else
# supplied json is invalid or does not satisfy condition
((invalid_count++)) ((invalid_count++))
invalid_channels+=("$file") invalid_channels+=("$file")
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment