2014-06-11 07:50:47 +00:00
|
|
|
# Common definitions for Rhizome test suites.
|
2014-06-27 07:59:29 +00:00
|
|
|
# Copyright 2012-2014 Serval Project Inc.
|
2012-07-06 04:02:21 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
# Some useful regular expressions. These must work for grep(1) (as basic
|
|
|
|
# expressions) and also in sed(1).
|
|
|
|
rexp_service='[A-Za-z0-9_]\+'
|
|
|
|
rexp_manifestid='[0-9a-fA-F]\{64\}'
|
2012-10-09 16:37:49 +00:00
|
|
|
rexp_bundlekey='[0-9a-fA-F]\{64\}'
|
2012-07-06 04:02:21 +00:00
|
|
|
rexp_bundlesecret="$rexp_bundlekey"
|
|
|
|
rexp_filehash='[0-9a-fA-F]\{128\}'
|
|
|
|
rexp_filesize='[0-9]\{1,\}'
|
|
|
|
rexp_version='[0-9]\{1,\}'
|
2013-12-30 07:39:56 +00:00
|
|
|
rexp_crypt='[01]'
|
2012-07-06 04:02:21 +00:00
|
|
|
rexp_date='[0-9]\{1,\}'
|
2013-01-23 03:35:18 +00:00
|
|
|
rexp_rowid='[0-9]\{1,\}'
|
2012-07-06 04:02:21 +00:00
|
|
|
|
2014-07-02 07:46:19 +00:00
|
|
|
BID_NONEXISTENT=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
|
|
|
|
|
2012-07-06 04:02:21 +00:00
|
|
|
assert_manifest_complete() {
|
|
|
|
local manifest="$1"
|
|
|
|
tfw_cat -v "$manifest"
|
|
|
|
assertGrep "$manifest" "^service=$rexp_service\$"
|
|
|
|
assertGrep "$manifest" "^id=$rexp_manifestid\$"
|
|
|
|
assertGrep "$manifest" "^BK=$rexp_bundlekey\$"
|
|
|
|
assertGrep "$manifest" "^date=$rexp_date\$"
|
|
|
|
assertGrep "$manifest" "^version=$rexp_version\$"
|
|
|
|
assertGrep "$manifest" "^filesize=$rexp_filesize\$"
|
2012-09-13 04:38:52 +00:00
|
|
|
if $GREP -q '^filesize=0$' "$manifest"; then
|
2012-07-16 08:54:46 +00:00
|
|
|
assertGrep --matches=0 "$manifest" "^filehash="
|
|
|
|
else
|
|
|
|
assertGrep "$manifest" "^filehash=$rexp_filehash\$"
|
|
|
|
fi
|
2012-09-13 04:38:52 +00:00
|
|
|
if $GREP -q '^service=file$' "$manifest"; then
|
2012-07-06 04:02:21 +00:00
|
|
|
assertGrep "$manifest" "^name="
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-10-17 07:40:39 +00:00
|
|
|
# Assertion function:
|
|
|
|
# - assert that the output of a "servald rhizome list" command exactly describes the given files
|
2012-07-06 04:02:21 +00:00
|
|
|
assert_rhizome_list() {
|
2013-01-23 03:35:18 +00:00
|
|
|
assertStdoutIs --stderr --line=1 -e '13\n'
|
|
|
|
assertStdoutIs --stderr --line=2 -e '_id:service:id:version:date:.inserttime:.author:.fromhere:filesize:filehash:sender:recipient:name\n'
|
2012-10-17 07:40:39 +00:00
|
|
|
local exactly=true
|
2012-10-04 04:52:06 +00:00
|
|
|
local re__inserttime="$rexp_date"
|
2012-10-17 07:40:39 +00:00
|
|
|
local re__fromhere='[01]'
|
|
|
|
local re__author="\($rexp_sid\)\{0,1\}"
|
|
|
|
local files=0
|
2013-09-30 07:09:58 +00:00
|
|
|
local manifestname=
|
|
|
|
local arg
|
|
|
|
for arg; do
|
|
|
|
case "$arg" in
|
|
|
|
--fromhere=*) re__fromhere="${arg#*=}";;
|
|
|
|
--author=*) re__author="${arg#*=}";;
|
|
|
|
--manifest=*) manifestname="${arg#*=}";;
|
2012-10-17 07:40:39 +00:00
|
|
|
--and-others) exactly=false;;
|
2013-09-30 07:09:58 +00:00
|
|
|
--*) error "unsupported option: $arg";;
|
2012-10-17 07:40:39 +00:00
|
|
|
*)
|
2013-09-30 07:09:58 +00:00
|
|
|
unpack_manifest_for_grep "$arg" "$manifestname"
|
2013-01-23 03:35:18 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 "^$rexp_rowid:$re_service:$re_manifestid:$re_version:$re_date:$re__inserttime:$re__author:$re__fromhere:$re_filesize:$re_filehash:$re_sender:$re_recipient:$re_name\$"
|
2012-10-17 07:40:39 +00:00
|
|
|
let files+=1
|
2013-09-30 07:09:58 +00:00
|
|
|
manifestname=
|
2012-10-17 07:40:39 +00:00
|
|
|
;;
|
2012-07-06 04:02:21 +00:00
|
|
|
esac
|
|
|
|
done
|
2012-10-17 07:40:39 +00:00
|
|
|
$exactly && assertStdoutLineCount --stderr '==' $(($files + 2))
|
2013-02-11 07:52:10 +00:00
|
|
|
rhizome_list_file_count=$(( $(replayStdout | wc -l) - 2 ))
|
|
|
|
}
|
|
|
|
|
|
|
|
rhizome_list_dump() {
|
|
|
|
local ncols
|
|
|
|
local -a headers
|
|
|
|
local readvars=
|
|
|
|
read ncols
|
|
|
|
local oIFS="$IFS"
|
|
|
|
IFS=:
|
|
|
|
read -r -a headers
|
|
|
|
IFS="$oIFS"
|
|
|
|
local hdr
|
|
|
|
local colvar
|
|
|
|
for hdr in "${headers[@]}"; do
|
|
|
|
readvars="$readvars __col_${hdr//[^A-Za-z0-9_]/_}"
|
|
|
|
done
|
|
|
|
eval local $readvars
|
|
|
|
for colvar in $readvars; do
|
|
|
|
eval "$colvar=ok"
|
|
|
|
done
|
|
|
|
local echoargs
|
|
|
|
for colname; do
|
|
|
|
case $colname in
|
|
|
|
manifestid|bundleid) colvar=__col_id;;
|
|
|
|
*) colvar="__col_${colname//[^A-Za-z0-9_]/_}";;
|
|
|
|
esac
|
|
|
|
eval [ -n "\"\${$colvar+ok}\"" ] || error "invalid column name: $colname" || return $?
|
|
|
|
echoargs="$echoargs $colname=\"\${$colvar}\""
|
|
|
|
done
|
|
|
|
IFS=:
|
|
|
|
while eval read -r $readvars; do
|
|
|
|
eval echo $echoargs
|
|
|
|
done
|
|
|
|
IFS="$oIFS"
|
2012-07-06 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_stdout_add_file() {
|
2013-09-30 07:09:58 +00:00
|
|
|
local manifestname=
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--manifest=*) manifestname="${1#*=}"; shift;;
|
|
|
|
--*) error "unsupported option: $1"; return 1;;
|
|
|
|
--) shift; break;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
2012-07-06 04:02:21 +00:00
|
|
|
[ $# -ge 1 ] || error "missing filename arg"
|
2013-09-30 07:09:58 +00:00
|
|
|
local filename="$1"
|
2012-07-06 04:02:21 +00:00
|
|
|
shift
|
2013-09-30 07:09:58 +00:00
|
|
|
unpack_manifest_for_grep "$filename" "$manifestname"
|
2012-12-31 02:37:52 +00:00
|
|
|
compute_filehash actual_filehash "$filename" actual_filesize
|
2013-09-30 07:09:58 +00:00
|
|
|
opt_service=
|
|
|
|
opt_manifestid=
|
|
|
|
opt_author=
|
|
|
|
opt_secret=
|
|
|
|
opt_BK=
|
|
|
|
opt_filesize=
|
2012-07-06 04:02:21 +00:00
|
|
|
opt_name=false
|
2012-09-13 04:38:52 +00:00
|
|
|
if replayStdout | $GREP -q '^service:file$'; then
|
2012-07-06 04:02:21 +00:00
|
|
|
opt_name=true
|
|
|
|
fi
|
2012-12-31 02:37:52 +00:00
|
|
|
opt_filehash=true
|
|
|
|
if [ "$re_crypt" = 1 ]; then
|
|
|
|
opt_filehash=false
|
|
|
|
fi
|
2013-09-27 13:04:22 +00:00
|
|
|
fieldnames='service|manifestid|author|secret|BK|filesize|filehash|name'
|
2012-07-06 04:02:21 +00:00
|
|
|
for arg; do
|
|
|
|
case "$arg" in
|
|
|
|
!+($fieldnames))
|
|
|
|
fieldname="${arg#!}"
|
|
|
|
eval opt_$fieldname=false
|
|
|
|
;;
|
|
|
|
+($fieldnames)=*)
|
|
|
|
value="${arg#*=}"
|
|
|
|
fieldname="${arg%%=*}"
|
|
|
|
assertStdoutGrep --matches=1 "^$fieldname:$value\$"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error "unsupported argument: $arg"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
${opt_service:-true} && assertStdoutGrep --matches=1 "^service:$re_service\$"
|
|
|
|
${opt_manifestid:-true} && assertStdoutGrep --matches=1 "^manifestid:$re_manifestid\$"
|
2013-09-27 13:04:22 +00:00
|
|
|
${opt_author:-true} && assertStdoutGrep --matches=1 "^\.author:$rexp_sid\$"
|
|
|
|
${opt_secret:-true} && assertStdoutGrep --matches=1 "^\.secret:$re_secret\$"
|
|
|
|
${opt_BK:-true} && assertStdoutGrep --matches=1 "^BK:$re_BK\$"
|
2012-12-31 02:37:52 +00:00
|
|
|
${opt_filesize:-true} && assertStdoutGrep --matches=1 "^filesize:$actual_filesize\$"
|
2012-09-13 04:38:52 +00:00
|
|
|
if replayStdout | $GREP -q '^filesize:0$'; then
|
2012-07-16 08:54:46 +00:00
|
|
|
assertStdoutGrep --matches=0 "^filehash:"
|
|
|
|
else
|
2012-12-31 02:37:52 +00:00
|
|
|
${opt_filehash:-true} && assertStdoutGrep --matches=1 "^filehash:$actual_filehash\$"
|
2012-07-16 08:54:46 +00:00
|
|
|
fi
|
2013-09-30 07:09:58 +00:00
|
|
|
${opt_name:-true} && assertStdoutGrep --matches=1 "^name:$re_name\$"
|
2012-07-06 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_stdout_import_bundle() {
|
2013-09-27 13:04:22 +00:00
|
|
|
# Output of "import bundle" is the same as "add file" but without the secret
|
|
|
|
# or author fields.
|
|
|
|
assert_stdout_add_file "$@" '!secret' '!author'
|
2012-07-06 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unpack_manifest_for_grep() {
|
|
|
|
local filename="$1"
|
2013-09-30 07:09:58 +00:00
|
|
|
local manifestname="${2:-$filename.manifest}"
|
2012-07-06 04:02:21 +00:00
|
|
|
re_service="$rexp_service"
|
|
|
|
re_manifestid="$rexp_manifestid"
|
|
|
|
re_version="$rexp_version"
|
2012-10-04 04:52:06 +00:00
|
|
|
re_date="$rexp_date"
|
2012-07-06 04:02:21 +00:00
|
|
|
re_secret="$rexp_bundlesecret"
|
2013-09-27 13:04:22 +00:00
|
|
|
re_BK="$rexp_bundlekey"
|
2012-10-09 07:13:34 +00:00
|
|
|
re_sender="\($rexp_sid\)\{0,1\}"
|
|
|
|
re_recipient="\($rexp_sid\)\{0,1\}"
|
2012-12-31 02:37:52 +00:00
|
|
|
re_filesize="$rexp_filesize"
|
2013-09-30 07:09:58 +00:00
|
|
|
re_filehash="\($rexp_filehash\)\{0,1\}"
|
2012-07-06 04:02:21 +00:00
|
|
|
re_name=$(escape_grep_basic "${filename##*/}")
|
2013-09-30 07:09:58 +00:00
|
|
|
if [ -e "$manifestname" ]; then
|
|
|
|
re_filesize=$($SED -n -e '/^filesize=/s///p' "$manifestname")
|
2014-07-07 08:24:52 +00:00
|
|
|
if [ "$re_filesize" = 0 ]; then
|
2012-12-31 02:37:52 +00:00
|
|
|
re_filehash=
|
|
|
|
else
|
2013-09-30 07:09:58 +00:00
|
|
|
re_filehash=$($SED -n -e '/^filehash=/s///p' "$manifestname")
|
2012-12-31 02:37:52 +00:00
|
|
|
fi
|
|
|
|
re_secret="$rexp_bundlesecret"
|
2013-09-30 07:09:58 +00:00
|
|
|
re_service=$($SED -n -e '/^service=/s///p' "$manifestname")
|
2012-10-09 07:13:34 +00:00
|
|
|
re_service=$(escape_grep_basic "$re_service")
|
2013-09-30 07:09:58 +00:00
|
|
|
re_manifestid=$($SED -n -e '/^id=/s///p' "$manifestname")
|
|
|
|
re_version=$($SED -n -e '/^version=/s///p' "$manifestname")
|
|
|
|
re_date=$($SED -n -e '/^date=/s///p' "$manifestname")
|
|
|
|
re_crypt=$($SED -n -e '/^crypt=/s///p' "$manifestname")
|
|
|
|
re_name=$($SED -n -e '/^name=/s///p' "$manifestname")
|
2012-12-31 02:37:52 +00:00
|
|
|
re_name=$(escape_grep_basic "$re_name")
|
2013-09-30 07:09:58 +00:00
|
|
|
re_BK=$($SED -n -e '/^BK=/s///p' "$manifestname")
|
|
|
|
re_sender=$($SED -n -e '/^sender=/s///p' "$manifestname")
|
|
|
|
re_recipient=$($SED -n -e '/^recipient=/s///p' "$manifestname")
|
2012-07-06 04:02:21 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_manifest_newer() {
|
|
|
|
local manifest1="$1"
|
|
|
|
local manifest2="$2"
|
|
|
|
# The new manifest must have a higher version than the original.
|
|
|
|
extract_manifest_version oldversion "$manifest1"
|
|
|
|
extract_manifest_version newversion "$manifest2"
|
|
|
|
assert [ $newversion -gt $oldversion ]
|
|
|
|
# The new manifest must have a different filehash from the original.
|
|
|
|
extract_manifest_filehash oldfilehash "$manifest1"
|
|
|
|
extract_manifest_filehash newfilehash "$manifest2"
|
|
|
|
assert [ $oldfilehash != $newfilehash ]
|
|
|
|
}
|
|
|
|
|
|
|
|
strip_signatures() {
|
|
|
|
for file; do
|
2012-09-13 04:38:52 +00:00
|
|
|
cat -v "$file" | $SED -e '/^^@/,$d' >"tmp.$file" && mv -f "tmp.$file" "$file"
|
2012-07-06 04:02:21 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-02-08 08:13:37 +00:00
|
|
|
extract_stdout_manifestid() {
|
|
|
|
extract_stdout_keyvalue "$1" manifestid "$rexp_manifestid"
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_stdout_version() {
|
|
|
|
extract_stdout_keyvalue "$1" version "$rexp_version"
|
|
|
|
}
|
|
|
|
|
2014-07-07 08:24:52 +00:00
|
|
|
extract_stdout_author_optional() {
|
|
|
|
extract_stdout_keyvalue_optional "$1" .author "$rexp_author"
|
|
|
|
}
|
|
|
|
|
2013-12-13 04:19:55 +00:00
|
|
|
extract_stdout_author() {
|
|
|
|
extract_stdout_keyvalue "$1" .author "$rexp_author"
|
|
|
|
}
|
|
|
|
|
2014-07-07 08:24:52 +00:00
|
|
|
extract_stdout_secret_optional() {
|
|
|
|
extract_stdout_keyvalue_optional "$1" .secret "$rexp_bundlesecret"
|
|
|
|
}
|
|
|
|
|
2012-07-06 04:02:21 +00:00
|
|
|
extract_stdout_secret() {
|
2013-09-27 13:04:22 +00:00
|
|
|
extract_stdout_keyvalue "$1" .secret "$rexp_bundlesecret"
|
2012-07-06 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 07:43:38 +00:00
|
|
|
extract_stdout_rowid() {
|
|
|
|
extract_stdout_keyvalue "$1" .rowid "$rexp_rowid"
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_stdout_inserttime() {
|
|
|
|
extract_stdout_keyvalue "$1" .inserttime "$rexp_date"
|
|
|
|
}
|
|
|
|
|
2012-07-06 04:02:21 +00:00
|
|
|
extract_stdout_BK() {
|
|
|
|
extract_stdout_keyvalue "$1" BK "$rexp_bundlekey"
|
|
|
|
}
|
|
|
|
|
2013-11-11 05:51:26 +00:00
|
|
|
extract_stdout_date() {
|
|
|
|
extract_stdout_keyvalue "$1" date "$rexp_date"
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_stdout_filesize() {
|
|
|
|
extract_stdout_keyvalue "$1" filesize "$rexp_filesize"
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_stdout_filehash() {
|
|
|
|
extract_stdout_keyvalue "$1" filehash "$rexp_filehash"
|
|
|
|
}
|
|
|
|
|
2013-12-13 07:11:26 +00:00
|
|
|
extract_stdout_crypt() {
|
|
|
|
extract_stdout_keyvalue "$1" crypt "$rexp_crypt"
|
|
|
|
}
|
|
|
|
|
2012-07-06 04:02:21 +00:00
|
|
|
extract_manifest() {
|
2014-03-12 03:52:38 +00:00
|
|
|
local __var="$1"
|
|
|
|
local __manifestfile="$2"
|
|
|
|
local __label="$3"
|
|
|
|
local __rexp="${4:-[^=]*}"
|
|
|
|
local __value=$($SED -n -e "/^$__label=$__rexp\$/s/^$__label=//p" "$__manifestfile")
|
|
|
|
[ -n "$__var" ] && eval $__var="\$__value"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_manifest_fields() {
|
|
|
|
local manifestfile="$1"
|
|
|
|
shift
|
|
|
|
assert --message="manifest file $manifestfile is readable" [ -r "$manifestfile" ]
|
|
|
|
[ $# -gt 0 ] || error "missing arguments"
|
|
|
|
local arg label value
|
|
|
|
for arg; do
|
|
|
|
case "$arg" in
|
|
|
|
!*)
|
|
|
|
assertGrep \
|
|
|
|
--matches=0 \
|
|
|
|
--message="$manifestfile contains no '$arg=' line" \
|
|
|
|
--dump-on-fail="$manifestfile" \
|
|
|
|
"$manifestfile" "^$arg="
|
|
|
|
;;
|
|
|
|
*=*)
|
|
|
|
label="${arg%%=*}"
|
|
|
|
value="${arg#*=}"
|
|
|
|
local mvalue
|
|
|
|
extract_manifest mvalue "$manifestfile" "$label"
|
|
|
|
assert \
|
|
|
|
--message="$manifestfile contains '$label=$value' line" \
|
|
|
|
--dump-on-fail="$manifestfile" \
|
|
|
|
[ "$mvalue" = "$value" ]
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
assertGrep \
|
|
|
|
--message="$manifestfile contains '$arg=' line" \
|
|
|
|
--dump-on-fail="$manifestfile" \
|
|
|
|
"$manifestfile" "^$arg="
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2012-07-06 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extract_manifest_service() {
|
|
|
|
extract_manifest "$1" "$2" service "$rexp_service"
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_manifest_id() {
|
|
|
|
extract_manifest "$1" "$2" id "$rexp_manifestid"
|
|
|
|
}
|
|
|
|
|
|
|
|
extract_manifest_BK() {
|
|
|
|
extract_manifest "$1" "$2" BK "$rexp_bundlekey"
|
|
|
|
}
|
|
|
|
|
2012-07-17 04:39:35 +00:00
|
|
|
extract_manifest_filesize() {
|
|
|
|
extract_manifest "$1" "$2" filesize "$rexp_filesize"
|
|
|
|
}
|
|
|
|
|
2012-07-06 04:02:21 +00:00
|
|
|
extract_manifest_filehash() {
|
|
|
|
extract_manifest "$1" "$2" filehash "$rexp_filehash"
|
|
|
|
}
|
|
|
|
|
2012-08-27 08:27:41 +00:00
|
|
|
extract_manifest_name() {
|
|
|
|
extract_manifest "$1" "$2" name ".*"
|
|
|
|
}
|
|
|
|
|
2012-07-06 04:02:21 +00:00
|
|
|
extract_manifest_version() {
|
|
|
|
extract_manifest "$1" "$2" version "$rexp_version"
|
|
|
|
}
|
|
|
|
|
2013-11-11 05:51:26 +00:00
|
|
|
extract_manifest_date() {
|
|
|
|
extract_manifest "$1" "$2" date "$rexp_date"
|
|
|
|
}
|
|
|
|
|
2013-01-03 05:42:24 +00:00
|
|
|
extract_manifest_crypt() {
|
|
|
|
extract_manifest "$1" "$2" crypt "$rexp_crypt"
|
|
|
|
}
|
|
|
|
|
2012-07-06 04:02:21 +00:00
|
|
|
compute_filehash() {
|
2013-09-30 06:41:35 +00:00
|
|
|
local _filehashvar="$1"
|
2012-07-06 04:02:21 +00:00
|
|
|
local _file="$2"
|
2013-09-30 06:41:35 +00:00
|
|
|
local _filesizevar="$3"
|
|
|
|
local _hash=
|
|
|
|
local _size=0
|
|
|
|
if [ -s "$_file" ]; then
|
|
|
|
local _hash=$($servald rhizome hash file "$_file") || error "$servald failed to compute file hash"
|
|
|
|
[ -z "${_hash//[0-9a-fA-F]/}" ] || error "file hash contains non-hex: $_hash"
|
|
|
|
[ "${#_hash}" -eq 128 ] || error "file hash incorrect length: $_hash"
|
|
|
|
local _size=$(( $(cat "$filename" | wc -c) + 0 ))
|
|
|
|
fi
|
|
|
|
[ -n "$_filehashvar" ] && eval $_filehashvar="\$_hash"
|
|
|
|
[ -n "$_filesizevar" ] && eval $_filesizevar="\$_size"
|
2012-07-06 04:02:21 +00:00
|
|
|
}
|
2012-08-27 07:37:44 +00:00
|
|
|
|
|
|
|
rhizome_http_server_started() {
|
|
|
|
local logvar=LOG${1#+}
|
2014-01-31 07:32:41 +00:00
|
|
|
$GREP 'HTTP SERVER START.*port=[0-9].*services=[^ ]*\<Rhizome\>' "${!logvar}"
|
2012-08-27 07:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get_rhizome_server_port() {
|
2014-04-29 05:34:20 +00:00
|
|
|
get_servald_http_server_port "$@"
|
2012-08-27 07:37:44 +00:00
|
|
|
}
|
2012-10-18 07:16:17 +00:00
|
|
|
|
|
|
|
# Predicate function:
|
|
|
|
# - return true if the file bundles identified by args BID[:VERSION] has been
|
|
|
|
# received by all the given instances args +I
|
|
|
|
# - does this by examining the server log files of the respective instances
|
|
|
|
# for tell-tale INFO messages
|
|
|
|
bundle_received_by() {
|
2012-11-05 04:13:57 +00:00
|
|
|
local -a rexps bundles
|
2012-10-18 07:16:17 +00:00
|
|
|
local restart=true
|
2012-11-05 04:13:57 +00:00
|
|
|
local arg bid version rexp bundle bundlefile i
|
|
|
|
local ret=0
|
2012-10-18 07:16:17 +00:00
|
|
|
for arg; do
|
|
|
|
case "$arg" in
|
|
|
|
+([0-9A-F])?(:+([0-9])))
|
2012-11-05 04:13:57 +00:00
|
|
|
$restart && rexps=() bundles=()
|
2012-10-18 07:16:17 +00:00
|
|
|
restart=false
|
|
|
|
bid="${arg%%:*}"
|
2014-03-03 04:40:59 +00:00
|
|
|
matches_rexp "$rexp_manifestid" "$bid" || error "invalid bundle ID: $bid" || return $?
|
2012-11-05 04:13:57 +00:00
|
|
|
bundles+=("$arg")
|
2012-10-18 07:16:17 +00:00
|
|
|
if [ "$bid" = "$arg" ]; then
|
2013-01-03 05:42:24 +00:00
|
|
|
rexps+=("RHIZOME ADD MANIFEST service=.* bid=$bid")
|
2012-10-18 07:16:17 +00:00
|
|
|
else
|
|
|
|
version="${arg#*:}"
|
2013-01-03 05:42:24 +00:00
|
|
|
rexps+=("RHIZOME ADD MANIFEST service=.* bid=$bid version=$version")
|
2012-10-18 07:16:17 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
+[A-Z])
|
2014-03-03 04:40:59 +00:00
|
|
|
tfw_nolog push_and_set_instance $arg || return $?
|
2013-06-18 02:43:14 +00:00
|
|
|
tfw_nolog assert_servald_server_status running
|
2012-11-05 04:13:57 +00:00
|
|
|
for ((i = 0; i < ${#bundles[*]}; ++i)); do
|
|
|
|
bundle="${bundles[$i]}"
|
|
|
|
rexp="${rexps[$i]}"
|
|
|
|
bundledir="$instance_dir/cache/bundles_received"
|
|
|
|
bundlefile="$bundledir/$bundle"
|
|
|
|
if [ ! -s "$bundlefile" ]; then
|
|
|
|
[ -d "$bundledir" ] || mkdir -p "$bundledir" || error "mkdir failed"
|
|
|
|
if grep "$rexp" "$instance_servald_log" >"$bundlefile"; then
|
|
|
|
tfw_log "bundle $bundle received by instance +$instance_name"
|
|
|
|
else
|
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
fi
|
2012-10-18 07:16:17 +00:00
|
|
|
done
|
|
|
|
restart=true
|
2014-06-27 05:37:26 +00:00
|
|
|
tfw_nolog pop_instance
|
2012-10-18 07:16:17 +00:00
|
|
|
;;
|
|
|
|
--stderr)
|
2012-11-05 04:13:57 +00:00
|
|
|
for ((i = 0; i < ${#bundles[*]}; ++i)); do
|
|
|
|
bundle="${bundles[$i]}"
|
|
|
|
rexp="${rexps[$i]}"
|
|
|
|
if replayStderr | grep "$rexp" >/dev/null; then
|
|
|
|
tfw_log "bundle $bundle received by ($executed)"
|
|
|
|
else
|
|
|
|
ret=1
|
|
|
|
fi
|
2012-10-18 07:16:17 +00:00
|
|
|
done
|
|
|
|
restart=true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error "invalid argument: $arg"
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2012-11-05 04:13:57 +00:00
|
|
|
return $ret
|
2012-10-18 07:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extract_manifest_vars() {
|
|
|
|
local manifest="${1?}"
|
|
|
|
extract_manifest_id BID "$manifest"
|
|
|
|
extract_manifest_version VERSION "$manifest"
|
|
|
|
extract_manifest_filesize FILESIZE "$manifest"
|
|
|
|
FILEHASH=
|
|
|
|
if [ "$FILESIZE" != '0' ]; then
|
|
|
|
extract_manifest_filehash FILEHASH "$manifest"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
rhizome_add_file() {
|
|
|
|
local name="$1"
|
2012-10-31 07:47:06 +00:00
|
|
|
local size="${2:-64}"
|
2013-02-20 04:14:29 +00:00
|
|
|
rhizome_add_files --size="$size" "$name"
|
|
|
|
extract_manifest_vars "$name.manifest"
|
|
|
|
}
|
|
|
|
|
|
|
|
rhizome_add_files() {
|
|
|
|
local size=64
|
2012-10-18 07:16:17 +00:00
|
|
|
local sidvar="SID$instance_name"
|
2013-02-20 04:14:29 +00:00
|
|
|
local -a names=()
|
|
|
|
for arg; do
|
|
|
|
case "$arg" in
|
|
|
|
--size=*)
|
|
|
|
size="${arg##*=}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
local name="$arg"
|
|
|
|
[ -e "$name" ] || create_file "$name" $size
|
|
|
|
executeOk_servald rhizome add file "${!sidvar}" "$name" "$name.manifest"
|
|
|
|
names+=("$name")
|
|
|
|
esac
|
|
|
|
done
|
2013-01-17 01:13:31 +00:00
|
|
|
executeOk_servald rhizome list
|
2013-02-20 04:14:29 +00:00
|
|
|
assert_rhizome_list --fromhere=1 --author="${!sidvar}" "${names[@]}" --and-others
|
2012-10-18 07:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rhizome_update_file() {
|
|
|
|
local orig_name="$1"
|
|
|
|
local new_name="$2"
|
|
|
|
[ -e "$new_name" ] || echo 'File $new_name' >"$new_name"
|
|
|
|
local sidvar="SID$instance_name"
|
|
|
|
[ "$new_name" != "$orig_name" ] && cp "$orig_name.manifest" "$new_name.manifest"
|
|
|
|
$SED -i -e '/^date=/d;/^filehash=/d;/^filesize=/d;/^version=/d;/^name=/d' "$new_name.manifest"
|
2013-02-13 06:19:52 +00:00
|
|
|
executeOk_servald rhizome add file "${!sidvar}" "$new_name" "$new_name.manifest"
|
|
|
|
executeOk_servald rhizome list
|
2012-10-18 07:16:17 +00:00
|
|
|
assert_rhizome_list --fromhere=1 "$new_name"
|
|
|
|
extract_manifest_vars "$new_name.manifest"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_rhizome_received() {
|
|
|
|
[ $# -ne 0 ] || error "missing arguments"
|
|
|
|
local name
|
2013-01-02 02:23:00 +00:00
|
|
|
local _id
|
2012-10-18 07:16:17 +00:00
|
|
|
for name; do
|
|
|
|
if [ -s "$name" ]; then
|
2013-01-02 02:23:00 +00:00
|
|
|
extract_manifest_id _id "$name.manifest"
|
|
|
|
executeOk_servald rhizome extract file "$_id" extracted
|
2012-10-18 07:16:17 +00:00
|
|
|
assert cmp "$name" extracted
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2014-06-27 07:59:29 +00:00
|
|
|
|
|
|
|
rhizome_add_bundles() {
|
|
|
|
local encrypted=false
|
|
|
|
case "$1" in
|
|
|
|
--encrypted) encrypted=true; shift;;
|
|
|
|
esac
|
|
|
|
local SID="${1?}"
|
|
|
|
shift
|
|
|
|
local n
|
|
|
|
for ((n = $1; n <= $2; ++n)); do
|
|
|
|
create_file file$n $((1000 + $n))
|
|
|
|
if $encrypted; then
|
|
|
|
echo "crypt=1" >file$n.manifest
|
|
|
|
fi
|
2014-07-01 12:23:03 +00:00
|
|
|
executeOk_servald rhizome add file "$SID" file$n file$n.manifest
|
2014-06-27 07:59:29 +00:00
|
|
|
extract_stdout_manifestid BID[$n]
|
|
|
|
extract_stdout_version VERSION[$n]
|
|
|
|
extract_stdout_filesize SIZE[$n]
|
|
|
|
extract_stdout_filehash HASH[$n]
|
|
|
|
extract_stdout_date DATE[$n]
|
|
|
|
extract_stdout_BK BK[$n]
|
|
|
|
extract_stdout_rowid ROWID[$n]
|
|
|
|
extract_stdout_author AUTHOR[$n]
|
|
|
|
extract_stdout_secret SECRET[$n]
|
|
|
|
extract_stdout_inserttime INSERTTIME[$n]
|
|
|
|
NAME[$n]=file$n
|
|
|
|
if $encrypted; then
|
|
|
|
extract_stdout_crypt CRYPT[$n]
|
|
|
|
assert [ "${CRYPT[$n]}" = 1 ]
|
|
|
|
else
|
|
|
|
CRYPT[$n]=
|
|
|
|
fi
|
|
|
|
executeOk_servald rhizome export file ${HASH[$n]} raw$n
|
|
|
|
if $encrypted; then
|
|
|
|
assert ! cmp file$n raw$n
|
|
|
|
else
|
|
|
|
assert cmp file$n raw$n
|
|
|
|
fi
|
|
|
|
[ "${ROWID[$n]}" -gt "${ROWID_MAX:-0}" ] && ROWID_MAX=${ROWID[$n]}
|
|
|
|
done
|
|
|
|
}
|
2014-07-02 07:46:19 +00:00
|
|
|
|
|
|
|
rhizome_delete_payload_blobs() {
|
|
|
|
local filehash
|
|
|
|
for filehash; do
|
|
|
|
assert --message="Rhizome external blob file exists, filehash=$filehash" [ -e "$SERVALINSTANCE_PATH/blob/$filehash" ]
|
|
|
|
rm -f "$SERVALINSTANCE_PATH/blob/$filehash"
|
|
|
|
done
|
|
|
|
}
|