Re: [PATCH] in place option for unexpand (original) (raw)

[Top][All Lists]


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


From: Pádraig Brady
Subject: Re: [PATCH] in place option for unexpand
Date: Mon, 21 Sep 2009 09:54:42 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Pádraig Brady wrote:

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:

tf=$(mktemp) 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" done

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?

cheers, Pádraig.

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?

Attached is a simple patch to support cp --attributes-only. Please be extra critical of this since it's a new interface. For example, perhaps it would be better to extend the --copy-contents option with a "never" parameter? Perhaps we don't need this at all?

Our "replace" script exapmle would now be of the form:

tf=$(mktemp) cleanup() { rm -f "$tf"; } trap "cleanup" EXIT for file in *.whatever; do cp --attr "$file" "$tf" unexpand "$file" > "$tf" && mv "$tf" "$file" done

cheers, Pádraig.

From a414bfbb4802649f768e3d222e542962cd038530 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden> Date: Mon, 21 Sep 2009 08:43:03 +0100 Subject: [PATCH] cp: add an option to only copy the file attributes


src/copy.c | 2 +- src/copy.h | 4 ++++ src/cp.c | 10 +++++++++- src/install.c | 1 + src/mv.c | 1 + 5 files changed, 16 insertions(+), 2 deletions(-)

1.6.2.5



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