bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lazy mode in tee


From: Bob Proulx
Subject: Re: lazy mode in tee
Date: Sat, 14 Mar 2009 16:38:46 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

Tomáš Mudruňka wrote:
> i was wroting small bash script which needs special behaviour of tee
> and i needed to reimplement it.

It reads like you actually need something slightly different.  You
want the new file to be either the old contents or the new contents
but nothing in between.  Which means that you would need to write to a
temporary file first and then rename it into the final location after
it has been fully written.

> The important lines looks like that:
> 
> while true; do
>       cat "$2" | ccrypt -e -K "$3" | tee-lazy "$1";
> done &

Perhaps something like this, it would need some more work:

dir=$(dirname "$1")
trap 'rm -f "$dir//$TMPFILE"' EXIT
while true; do
  TMPFILE=$(mktemp "$dir//mytmpfile.XXXXXXXX") || exit 1
  ccrypt -e -K "$3" < "$2" | tee "$TMPFILE"
  mv -f "$TMPFILE" "$1"
done

And much of the current topical discussion of ext4 buffer flush
ordering says that the above isn't safe in the presense of system
crashes.  File data into $TMPFILE needs to be flushed to disk first.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]