Add Chris Demetriou's --unlink changes.

I know that I said earlier that this should be unconditional behaviour,
but I thought about it a little more and concluded that the principle of least
surprise dictates that I make it an option.
This commit is contained in:
jkh 1994-06-28 07:12:43 +00:00
parent 0e44d1d495
commit 032e36e1c3
3 changed files with 40 additions and 0 deletions

View File

@ -310,6 +310,14 @@ extract_archive ()
fd = 1;
goto extract_file;
}
if (f_unlink && !f_keep) {
if (unlink(skipcrud + current_file_name) == -1)
if (errno != ENOENT)
msg_perror ("Could not unlink %s",
skipcrud + current_file_name);
}
#ifdef O_CTG
/*
* Contiguous files (on the Masscomp) have to specify
@ -556,6 +564,13 @@ extract_archive ()
{
struct stat st1, st2;
if (f_unlink && !f_keep) {
if (unlink(skipcrud + current_file_name) == -1)
if (errno != ENOENT)
msg_perror ("Could not unlink %s",
skipcrud + current_file_name);
}
check = link (current_link_name, skipcrud + current_file_name);
if (check == 0)
@ -578,6 +593,13 @@ extract_archive ()
#ifdef S_ISLNK
case LF_SYMLINK:
again_symlink:
if (f_unlink && !f_keep) {
if (unlink(skipcrud + current_file_name) == -1)
if (errno != ENOENT)
msg_perror ("Could not unlink %s",
skipcrud + current_file_name);
}
check = symlink (current_link_name,
skipcrud + current_file_name);
/* FIXME, don't worry uid, gid, etc... */
@ -602,6 +624,13 @@ extract_archive ()
#endif
#if defined(S_IFCHR) || defined(S_IFBLK)
make_node:
if (f_unlink && !f_keep) {
if (unlink(skipcrud + current_file_name) == -1)
if (errno != ENOENT)
msg_perror ("Could not unlink %s",
skipcrud + current_file_name);
}
check = mknod (current_file_name + skipcrud,
(int) hstat.st_mode, (int) hstat.st_rdev);
if (check != 0)
@ -619,6 +648,13 @@ extract_archive ()
/* If local system doesn't support FIFOs, use default case */
case LF_FIFO:
make_fifo:
if (f_unlink && !f_keep) {
if (unlink(skipcrud + current_file_name) == -1)
if (errno != ENOENT)
msg_perror ("Could not unlink %s",
skipcrud + current_file_name);
}
check = mkfifo (current_file_name + skipcrud,
(int) hstat.st_mode);
if (check != 0)

View File

@ -181,6 +181,8 @@ struct option long_options[] =
{"force-local", 0, &f_force_local, 1},
{"atime-preserve", 0, &f_atime_preserve, 1},
{"unlink", 0, &f_unlink, 1},
{0, 0, 0, 0}
};
@ -757,6 +759,7 @@ Other options:\n\
filter the archive through PROG (which must accept -d)\n\
--block-compress block the output of compression program for tapes\n\
-[0-7][lmh] specify drive and density\n\
--unlink unlink files before creating them\n\
", stdout);
}

View File

@ -231,6 +231,7 @@ TAR_EXTERN char *f_volno_file; /* --volno-file */
TAR_EXTERN int f_force_local; /* --force-local */
TAR_EXTERN int f_atime_preserve;/* --atime-preserve */
TAR_EXTERN int f_compress_block; /* --compress-block */
TAR_EXTERN int f_unlink; /* --unlink */
/*
* We default to Unix Standard format rather than 4.2BSD tar format.