diff --git a/app/crawler/notea_test.sh b/app/crawler/.notea_test.sh similarity index 100% rename from app/crawler/notea_test.sh rename to app/crawler/.notea_test.sh diff --git a/app/crawler/notnotea.sh b/app/crawler/notnotea.sh index facd131..476760a 100644 --- a/app/crawler/notnotea.sh +++ b/app/crawler/notnotea.sh @@ -22,9 +22,6 @@ notnotea() ( } _recurse_ids() { - _echo() { - echo "$*" || true - } local prefix="$1" local json="$2" local b64lines="$(echo "$json" | jq -r '.Branches | keys[]' | base64)" @@ -35,31 +32,31 @@ notnotea() ( line="$(echo "$line" | base64 --decode)" local subfix="$(printf "%s/%s" "$prefix" "$line")" subfix="${subfix#/}" - _echo "$subfix" + if ! _is_deleted "$subfix"; then + echo "$subfix" + fi _recurse_ids "$subfix" "$(echo "$json" | jq ".Branches.$line")" done } meta() { - local key="$1" - key="${key//\//.Branches.}" - _tree | jq -c ".Branches.$key.Leaf" + local id="$1" + id="${id//\//.Branches.}" + _tree | jq -c ".Branches.$id.Leaf" } _is_deleted() { - local id="$1" - if [ "$id" == "root" ] || [ "$id" == "null" ]; then - return 1 - fi - local meta="$(meta "$id")" - if echo "$meta" | jq .deleted | grep -q 1; then - return 0 - fi - local pid="$(echo "$meta" | jq -r .pid)" - if [ -z "$pid" ]; then - return 0 - fi - _is_deleted "$pid" + local id="$1" + while [ -n "$id" ]; do + if meta "$id" | jq .Deleted | grep -q true; then + return 0 + fi + if [ "$id" == "${id%/*}" ]; then + return 1 + fi + id="${id%/*}" + done + return 1 } _tree_ids() { diff --git a/app/crawler/notnotea_test.sh b/app/crawler/notnotea_test.sh index 9241630..0dce194 100644 --- a/app/crawler/notnotea_test.sh +++ b/app/crawler/notnotea_test.sh @@ -1,6 +1,6 @@ #! /bin/bash -test__recurse_ids() { +test_ids() { local two_levels='{ "Branches": { "id": { @@ -12,9 +12,13 @@ test__recurse_ids() { } } }' - (notnotea _recurse_ids "" "$two_levels"; true) | grep -q '^id$' || return 101 - (notnotea _recurse_ids "" "$two_levels"; true) | tail -n 1 | grep -q '^id\/subid$' || return 102 - notnotea _recurse_ids "" "$two_levels" | wc -l | grep -q 2 || return 103 + notnotea eval "$(cat < /dev/null || return 101 + (ids; true) | grep '^id\/subid$' > /dev/null || return 102 + ids | wc -l | grep 2 > /dev/null || return 103 +EOF +)" } test_meta() { @@ -33,8 +37,30 @@ test_meta() { }' notnotea eval "$(cat <