[Top][All Lists]

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

Re: [PATCH] in place option for unexpand

From: Pádraig Brady
Subject: Re: [PATCH] in place option for unexpand
Date: Sun, 22 Mar 2009 01:06:27 +0000
User-agent: Thunderbird (X11/20071008)

Sami Kerola wrote:
> Good weekend,
> If you consider in-line option is useful for unexpand I could wrote
> another patch for expand command which will do the same thing.

Thanks for this. I'm wondering about usefulness to other coreutils.
Perhaps fmt,fold,nl,tac,tr would also benefit in addition to expand & unexpand?
On the other hand it's simple enough to achieve this using existing commands:

cleanup() { rm -f "$tf"; }
trap "cleanup" EXIT
for file in *.whatever; do
    touch --reference="$file" "$tf"
    chmod --reference="$file" "$tf"
    unexpand "$file" > "$tf" &&
    mv "$tf" "$file"

That as well as being more flexible will also give you
auto cleanup of the temp file on Ctrl-C for example.
You would have to add signal handling to your patch to do that.
So what do people think about bringing the above logic
internal to certain utils?

BTW, I like the way you use $TMPDIR etc. contrary to the `sed` --in-place
option which uses a tmp file in the same dir as the original.
Using the same dir will fail in the case you've a file in a readonly dir
bind mounted to a writeable location for example.
On the otherhand it requires more code to support. For example
I think your rename() will fail if $TMPDIR is on
a different filesystem to the original file?


p.s. wouldn't it be useful to give cp an option to copy attributes
but not data, i.e. instead of the touch and chmod in the example above,
one could do: cp --attributes-only --preserve=all "$file" "$tf"
or alternatively give a --preserve=all option to `touch`?

reply via email to

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