diff --git a/base b/base index 0b0b8a721..84f56d3fb 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 0b0b8a72192909dcdce43792ae8765a9589eaaf8 +Subproject commit 84f56d3fb8f6883923ea5a0707ee26753259d47b diff --git a/frontend/ui/otamanager.lua b/frontend/ui/otamanager.lua index 0db71edfd..081534650 100644 --- a/frontend/ui/otamanager.lua +++ b/frontend/ui/otamanager.lua @@ -308,8 +308,10 @@ function OTAManager:fetchAndProcessUpdate() timeout = 3, }) -- Clear the installed package, as well as the complete/incomplete update download - os.execute("rm " .. self.installed_package) - os.execute("rm " .. self.updated_package .. "*") + os.execute("rm -f " .. self.installed_package) + os.execute("rm -f " .. self.updated_package .. "*") + -- As well as temporary files, in case zsync went kablooey too early... + os.execute("rm -f ./rcksum-*") -- And then relaunch zsync in full download mode... UIManager:scheduleIn(1, function() if OTAManager:zsync(true) == 0 then @@ -326,7 +328,7 @@ function OTAManager:fetchAndProcessUpdate() UIManager:show(ConfirmBox:new{ text = _("Error updating KOReader. Would you like to delete temporary files?"), ok_callback = function() - os.execute("rm " .. ota_dir .. "ko*") + os.execute("rm -f " .. ota_dir .. "ko*") end, }) end @@ -334,7 +336,9 @@ function OTAManager:fetchAndProcessUpdate() end, choice2_text = _("Abort"), choice2_callback = function() - os.execute("rm " .. ota_dir .. "ko*") + os.execute("rm -f " .. ota_dir .. "ko*") + os.execute("rm -f " .. self.updated_package .. "*") + os.execute("rm -f ./rcksum-*") end, }) end diff --git a/platform/common/spinning_zsync b/platform/common/spinning_zsync index 756c08edb..02ec018f0 100755 --- a/platform/common/spinning_zsync +++ b/platform/common/spinning_zsync @@ -1,5 +1,16 @@ #!/bin/sh +# We're going to need to remember failures from the *left* side of a pipeline... +# shellcheck disable=SC2039 +if set -o pipefail 2>/dev/null; then + WITH_PIPEFAIL="true" +else + # But because we can't have nice things, some devices (hi, Kindle) may use an extremely old busybox build, + # one in which pipefail was not yet implemented, + # (it appeared in busybox 1.16.0, and is contingent on bash compatibility being enabled in ash). + WITH_PIPEFAIL="true" +fi + # Figure out whether that's a delta or a full download given the number of arguments passed... if [ $# -lt 7 ]; then ZSYNC_MESSAGE="Downloading update data" @@ -7,43 +18,34 @@ else ZSYNC_MESSAGE="Computing zsync delta" fi -# Small zsync wrapper so we can get a pretty spinner while it works... -./fbink -q -y -7 -pmh "${ZSYNC_MESSAGE} !" +# Small zsync wrapper so we can print its output while it works... +./fbink -q -y -7 -pmh "${ZSYNC_MESSAGE} . . ." # Clear any potential leftover from the local OTA tarball creation. ./fbink -q -y -6 -pm ' ' -# Spin in the background while we work ;). -( - # See https://stackoverflow.com/questions/2685435 for inspiration - # as well as https://www.npmjs.com/package/cli-spinners - # & https://github.com/swelljoe/spinner - # http://www.fileformat.info/info/unicode/block/block_elements/list.htm - ## - # Simple bars, they look better when a bit smoother, with a snappier interval (~250ms) - #SPINNER="� ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁" - #SPINNER="� ▏ ▎ ▍ ▌ ▋ ▊ ▉ █ ▉ ▊ ▋ ▌ ▍ ▎ ▏" - # Spinning blocks - SPINNER="▖ ▘ ▝ ▗" - #SPINNER="▜ ▟ ▙ ▛" - # Snaking blocks - #SPINNER="▌ ▀ ▐ ▄" - #SPINNER="▌ ▛ ▀ ▜ ▐ ▟ ▄ ▙" - while :; do - for spin in ${SPINNER}; do - usleep 500000 2>/dev/null || sleep 0.5 - # NOTE: Throw stderr to the void because I'm cheating w/ U+FFFD for a blank character, - # which FBInk replaces by a blank, but not before shouting at us on stderr ;). - ./fbink -q -y -7 -pmh "${ZSYNC_MESSAGE} ${spin}" 2>/dev/null - done - done -) & - # Launch zsync2, and remember its exit code... -./zsync2 "$@" -rc=$? +# We'll be piping its output to FBInk in order to print it live, in a smaller font than usual... +# NOTE: This depends on an undocumented FBInk hack (-z) in order to deal with the progress bars (and their CR) sanely. +rc=0 -# Kill the spinner subshell now that we're done -kill -15 $! +if [ "${WITH_PIPEFAIL}" = "true" ]; then + # We can use pipefail, let the shell do the heavy lifting for us... + ./zsync2 "$@" 2>&1 | ./fbink -q -z -pm -F scientifica + rc=$? +else + # We cannot use pipefail, extreme shell wizardry is required... + # Pure magic courtesy of https://unix.stackexchange.com/a/70675 + # Much more compact than the stock answer from the Usenet shell FAQ: http://cfajohnson.com/shell/cus-faq-2.html#Q11 + { { { { + ./zsync2 "$@" 2>&1 3>&- 4>&- + echo $? >&3 + } | ./fbink -q -z -pm -F scientifica >&4; } 3>&1; } | { + read -r xs + exit "${xs}" + }; } 4>&1 + + rc=$? +fi -# And return with zsync's exit code, not kill's ;). +# And return with zsync's exit code exit ${rc}