summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBo Ørsted Andresen <bo.andresen@zlin.dk>2007-02-28 20:18:29 +0000
committerBo Ørsted Andresen <bo.andresen@zlin.dk>2007-02-28 20:18:29 +0000
commit9c7365311c8f260dff098d8a40a3a7e36ed1b886 (patch)
tree4d9d09832527b36c270de80d5245b567b609acc3
parent79ce681100d4cd4e98d9bd997b793517310f45bc (diff)
downloadwgetpaste-9c7365311c8f260dff098d8a40a3a7e36ed1b886.tar.gz
Fall back to using --post-data if a temporary file for --post-file could not be created.
-rwxr-xr-xwgetpaste25
1 files 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