On Mon 10. of December 2007 23:14:32 Paul Eggert wrote: > Radek Brich <[EMAIL PROTECTED]> writes: > > Are users supposed to avoid this > > Yes. (:-) > > > maybe there are other ways (e.g. somehow test if file > > descriptor points to stdout). > > Yes, that would be much better than trying to support /dev/stdout, > /dev/fd/0, etc., etc. It would also handle this case: > > tar -cf foo ... >foo > > Can you prepare a patch along those lines?
Well, I made a patch based on i-node comparison, see attachment. It works in
all cases you named. Although it'd need some cleaning, I'd like to hear what
you think about the idea?
Despite the other replies, I think some users could appreciate this fixed.
--
Radek Brich
/__\ Base OS/core services
~~~~~~~~ Red Hat Czech, Brno
diff -up tar-1.17/src/buffer.c.stdoutlist tar-1.17/src/buffer.c
--- tar-1.17/src/buffer.c.stdoutlist 2007-06-01 12:17:10.000000000 +0200
+++ tar-1.17/src/buffer.c 2007-12-11 13:01:28.000000000 +0100
@@ -465,6 +465,10 @@ _open_archive (enum access_mode wanted_a
records_read = 0;
+ struct stat st_stdout, st_archive;
+ fstat(STDOUT_FILENO, &st_stdout);
+ stat(archive_name_array[0], &st_archive);
+
if (use_compress_program_option)
{
switch (wanted_access)
@@ -486,10 +490,12 @@ _open_archive (enum access_mode wanted_a
if (!index_file_name
&& wanted_access == ACCESS_WRITE
- && strcmp (archive_name_array[0], "-") == 0)
+ && (strcmp (archive_name_array[0], "-") == 0
+ || st_archive.st_ino == st_stdout.st_ino))
stdlis = stderr;
}
- else if (strcmp (archive_name_array[0], "-") == 0)
+ else if (strcmp (archive_name_array[0], "-") == 0
+ || st_archive.st_ino == st_stdout.st_ino)
{
read_full_records = true; /* could be a pipe, be safe */
if (verify_option)
signature.asc
Description: This is a digitally signed message part.
