From 481f8de56aec8863d7880eee552a87fbb327bcb2 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Fri, 4 Apr 2014 16:04:24 +1300 Subject: [PATCH] Permit cache-url to work with fifos. This makes it easier to work with temporary files - less traps scattered around higher layer code. Change-Id: I2fdd93115a7b0d289c2e28f8c133d4059de75b87 --- elements/cache-url/bin/cache-url | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/elements/cache-url/bin/cache-url b/elements/cache-url/bin/cache-url index b98c11ba..37aff537 100755 --- a/elements/cache-url/bin/cache-url +++ b/elements/cache-url/bin/cache-url @@ -24,8 +24,14 @@ url=$1 dest=$2 time_cond= -mkdir -p $(dirname $dest) -tmp=$(mktemp $(dirname $dest)/.download.XXXXXXXX) +if [ -p $dest ]; then + type="fifo" + tmp=$(mktemp --tmpdir download.XXXXXXXX) +else + type="normal" + mkdir -p $(dirname $dest) + tmp=$(mktemp $(dirname $dest)/.download.XXXXXXXX) +fi if [ -f $dest -a -s $dest ] ; then time_cond="-z $dest" @@ -44,7 +50,12 @@ if [ "$rcode" == "200" -o "${url:0:7}" == "file://" ] ; then rm -f $tmp else echo $success - mv $tmp $dest + if [ "fifo" = "$type" ]; then + cp $tmp $dest + rm $tmp + else + mv $tmp $dest + fi fi # 213 is the response to a ftp MDTM command, curl outputs a 213 as the status # if the url redirected to a ftp server and Not-Modified