RFC: alias tar="tar --backup" ?

Soren Hansen sh at linux2go.dk
Fri May 18 01:52:53 UTC 2007

On Thu, May 17, 2007 at 06:03:18PM -0700, Micah Cowan wrote:
> > A completely different approach could be that the calls that
> > actually write to a file check that the file does not exist. You
> > could activate this with a system-wide flag, but I strongly suspect
> > that this would be more work than the few words it took for me to
> > write the idea.
> The call of which you speak (open()) already does this, unless you
> tell it that you specifically wish to overwrite files (which tar
> does).

That's not quite right.

Usually, you'll just pass the O_CREAT and O_TRUNC flags to open(2) in
order to just open the file (creating it if it doesn't exist already),
while you have to explicitly give it the O_EXCL flag to bail out if the
file already exists. Passing --backup to tar makes it check if it should
make a backup of the file, does so, and then proceeds to open the file
with (O_WRONLY | O_BINARY | O_CREAT | O_TRUNC) unless you pass it '-k',
in which case O_TRUNC is replaced with O_EXCL.

| Soren Hansen    | Linux2Go                  | http://Linux2Go.dk/ |
| Seniorkonsulent | Lindholmsvej 42, 2. TH    | +45 46 90 26 42     |
| sh at linux2go.dk  | 9400 Norresundby, Denmark | GPG key: E8BDA4E3   |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-devel-discuss/attachments/20070518/08881e14/attachment.sig>

More information about the Ubuntu-devel-discuss mailing list