PR/19339: Martin Weber: Tar fails to append on empty files and exits with

0. Revert previous change for PR/18689. We always want to exit with
an error if we could not determine the archive format. Instead,
treat empty files specially. On list/extract we turn into no/op.
On append, we turn into archive.
This commit is contained in:
christos 2002-12-10 18:33:26 +00:00
parent 174b474772
commit 8461b5b85f
3 changed files with 29 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ar_io.c,v 1.28 2002/12/05 01:38:05 grant Exp $ */
/* $NetBSD: ar_io.c,v 1.29 2002/12/10 18:33:26 christos Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94";
#else
__RCSID("$NetBSD: ar_io.c,v 1.28 2002/12/05 01:38:05 grant Exp $");
__RCSID("$NetBSD: ar_io.c,v 1.29 2002/12/10 18:33:26 christos Exp $");
#endif
#endif /* not lint */
@ -221,6 +221,22 @@ ar_open(const char *name)
else
artyp = ISREG;
/*
* Special handling for empty files.
*/
if (artyp == ISREG && arsb.st_size == 0) {
switch (act) {
case LIST:
case EXTRACT:
return -1;
case APPND:
act = ARCHIVE;
return -1;
case ARCHIVE:
break;
}
}
/*
* make sure we beyond any doubt that we only can unlink regular files
* we created

View File

@ -1,4 +1,4 @@
/* $NetBSD: ar_subs.c,v 1.20 2002/10/18 11:54:22 itojun Exp $ */
/* $NetBSD: ar_subs.c,v 1.21 2002/12/10 18:33:26 christos Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)ar_subs.c 8.2 (Berkeley) 4/18/94";
#else
__RCSID("$NetBSD: ar_subs.c,v 1.20 2002/10/18 11:54:22 itojun Exp $");
__RCSID("$NetBSD: ar_subs.c,v 1.21 2002/12/10 18:33:26 christos Exp $");
#endif
#endif /* not lint */
@ -1267,6 +1267,6 @@ get_arc(void)
/*
* we cannot find a header, bow, apologize and quit
*/
tty_warn(0, "Sorry, unable to determine archive format.");
tty_warn(1, "Sorry, unable to determine archive format.");
return(-1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pax.c,v 1.22 2002/10/20 00:40:29 christos Exp $ */
/* $NetBSD: pax.c,v 1.23 2002/12/10 18:33:26 christos Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
#if 0
static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94";
#else
__RCSID("$NetBSD: pax.c,v 1.22 2002/10/20 00:40:29 christos Exp $");
__RCSID("$NetBSD: pax.c,v 1.23 2002/12/10 18:33:26 christos Exp $");
#endif
#endif /* not lint */
@ -298,6 +298,12 @@ main(int argc, char **argv)
if (gzip_program != NULL)
err(1, "can not gzip while appending");
append();
/*
* Check if we tried to append on an empty file and
* turned into ARCHIVE mode.
*/
if (act == ARCHIVE)
archive();
break;
case COPY:
copy();