fix(quickget): emit curl progress and size to stdout when piped
When stdout is not a TTY, GUI frontends and scripts receive no download feedback because curl suppresses its progress output. This fix adds two behaviours when stdout is a pipe: - A HEAD request fetches the correct total file size (Content-Length) and emits it as "content-length: N" to stdout before downloading. Using a separate HEAD request avoids the ambiguity of --dump-header with redirects or 206 resume responses. - --stderr - is added to the curl download so the --progress-bar output is written to stdout, letting callers parse real-time percentage. Normal terminal behaviour is completely unchanged. Fixes #1921 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2d9f6c9458
commit
4df2949bc0
12
quickget
12
quickget
|
|
@ -1464,7 +1464,17 @@ function web_get() {
|
|||
echo "- URL: ${URL}"
|
||||
fi
|
||||
|
||||
if ! curl --disable --progress-bar --location --output "${DIR}/${FILE}" --continue-at - --user-agent "${USER_AGENT}" "${HEADERS[@]}" -- "${URL}"; then
|
||||
local PIPE_OPTS=()
|
||||
if [ ! -t 1 ]; then
|
||||
local CONTENT_LENGTH
|
||||
CONTENT_LENGTH=$(curl --disable --silent --head --location \
|
||||
--write-out '%{content_length_download}' --output /dev/null \
|
||||
--user-agent "${USER_AGENT}" "${HEADERS[@]}" -- "${URL}" 2>/dev/null)
|
||||
[ -n "${CONTENT_LENGTH}" ] && echo "content-length: ${CONTENT_LENGTH}"
|
||||
PIPE_OPTS=("--stderr" "-")
|
||||
fi
|
||||
|
||||
if ! curl --disable --progress-bar "${PIPE_OPTS[@]}" --location --output "${DIR}/${FILE}" --continue-at - --user-agent "${USER_AGENT}" "${HEADERS[@]}" -- "${URL}"; then
|
||||
echo "ERROR! Failed to download ${URL} with curl."
|
||||
rm -f "${DIR}/${FILE}"
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Reference in New Issue