Files
RemoteDesk/packaging/linux/verify-file-resume.sh
曾志威 5db6b9ef68
ci / rust (push) Canceled after 0s
ci / web (push) Canceled after 0s
ci / package-preview (push) Canceled after 0s
ci / package-installer (push) Canceled after 0s
ci / linux-agent (push) Canceled after 0s
ci / edge-service (push) Canceled after 0s
ci / coturn-pop (push) Canceled after 0s
ci / package-windows-host (push) Canceled after 0s
Initial commit
2026-08-14 00:35:42 +08:00

46 lines
1.5 KiB
Bash

#!/bin/sh
set -eu
helper=${1:-target/debug/remotedesk-file-session}
case "$helper" in
/*) ;;
*) helper=$(CDPATH= cd -- "$(dirname -- "$helper")" && pwd)/$(basename -- "$helper") ;;
esac
if [ ! -x "$helper" ]; then
echo "file helper is not executable: $helper" >&2
exit 1
fi
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
export HOME="$work/home"
mkdir -p "$HOME/Documents"
content=abcdefghij
sha256=$(printf %s "$content" | sha256sum | cut -d ' ' -f 1)
transfer_id=0123456789abcdef0123456789abcdef
if printf abcd | "$helper" upload Documents/report.bin 10 "$sha256" "$transfer_id" \
>"$work/first.out" 2>"$work/first.err"; then
echo "interrupted upload unexpectedly completed" >&2
exit 1
fi
grep -q '"offset":0' "$work/first.out"
partial="$HOME/Documents/.report.bin.remotedesk-$transfer_id.part"
test "$(cat "$partial")" = abcd
printf efghij | "$helper" upload Documents/report.bin 10 "$sha256" "$transfer_id" \
>"$work/second.out"
grep -q '"offset":4' "$work/second.out"
test "$(cat "$HOME/Documents/report.bin")" = "$content"
test ! -e "$partial"
"$helper" download Documents/report.bin 4 >"$work/download.out"
header=$(sed -n '1p' "$work/download.out")
grep -q '"size":10' "$work/download.out"
grep -q "\"sha256\":\"$sha256\"" "$work/download.out"
header_bytes=$((${#header} + 1))
tail -c "+$((header_bytes + 1))" "$work/download.out" >"$work/remainder"
test "$(cat "$work/remainder")" = efghij
echo "Linux upload and download resume verification passed"