From 9c7365311c8f260dff098d8a40a3a7e36ed1b886 Mon Sep 17 00:00:00 2001 From: Bo Ørsted Andresen Date: Wed, 28 Feb 2007 20:18:29 +0000 Subject: Fall back to using --post-data if a temporary file for --post-file could not be created. --- wgetpaste | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/wgetpaste b/wgetpaste index f3b83f5..5df1c64 100755 --- a/wgetpaste +++ b/wgetpaste @@ -542,27 +542,34 @@ warn_size 1>&2 # create temp file (wget is much more reliable reading large input from a file than from the cli directly TEMPFILE="$(mktemp /tmp/wgetpaste.XXXXXX)" -[[ -f "${TEMPFILE}" ]] || die "Failed to create a temporary file." 1>&2 +if [[ -n "${TEMPFILE}" ]] && [[ -f "${TEMPFILE}" ]]; then + # write paste data to the temporary file + post_data > "${TEMPFILE}" || die "Failed to write to temporary file: \"${TEMPFILE}\"." -# write paste data to the temporary file -post_data > "${TEMPFILE}" || die "Failed to write to temporary file: \"${TEMPFILE}\"." + WGET_ARGS="--post-file=${TEMPFILE}" +else + # fall back to using --post-data if the temporary file could not be created + WGET_ARGS="--post-data=$(post_data | sed -e 's|$|%0a|g' -e 's|\t|%09|g' | tr -d '\n')" +fi # set recipient RECIPIENT="$(get_recipient "raw")" # paste it -WGET_ARGS="--tries=5 --timeout=60 --post-file=${TEMPFILE}" +WGET_ARGS="--tries=5 --timeout=60 ${WGET_ARGS}" if ! need_stdout && [[ ! ${DEBUG} ]] && [[ -w /dev/null ]]; then OUTPUT="$(wget -O /dev/null ${WGET_ARGS} ${RECIPIENT} 2>&1)" else OUTPUT="$(wget -O - ${WGET_ARGS} ${RECIPIENT} 2>&1)" fi -# clean temporary file -if [[ ! ${DEBUG} ]]; then - rm "${TEMPFILE}" || echo "Failed to remove temporary file: \"${TEMPFILE}\"." 1>&2 -else - echo "Left temporary file: \"${TEMPFILE}\" alone for debugging purposes." +# clean temporary file if it was created +if [[ -n "${TEMPFILE}" ]] && [[ -f "${TEMPFILE}" ]]; then + if [[ ! ${DEBUG} ]]; then + rm "${TEMPFILE}" || echo "Failed to remove temporary file: \"${TEMPFILE}\"." 1>&2 + else + echo "Left temporary file: \"${TEMPFILE}\" alone for debugging purposes." + fi fi # get the url -- cgit v1.2.3