From 032e36e1c30eb07d06117e3236c96edc221d55b5 Mon Sep 17 00:00:00 2001 From: jkh Date: Tue, 28 Jun 1994 07:12:43 +0000 Subject: 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. --- gnu/usr.bin/tar/extract.c | 36 ++++++++++++++++++++++++++++++++++++ gnu/usr.bin/tar/tar.c | 3 +++ gnu/usr.bin/tar/tar.h | 1 + 3 files changed, 40 insertions(+) (limited to 'gnu/usr.bin') diff --git a/gnu/usr.bin/tar/extract.c b/gnu/usr.bin/tar/extract.c index d162cab..57f8222 100644 --- a/gnu/usr.bin/tar/extract.c +++ b/gnu/usr.bin/tar/extract.c @@ -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) diff --git a/gnu/usr.bin/tar/tar.c b/gnu/usr.bin/tar/tar.c index 9382582..ec2c3d1 100644 --- a/gnu/usr.bin/tar/tar.c +++ b/gnu/usr.bin/tar/tar.c @@ -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); } diff --git a/gnu/usr.bin/tar/tar.h b/gnu/usr.bin/tar/tar.h index c3fec78..46d29d8 100644 --- a/gnu/usr.bin/tar/tar.h +++ b/gnu/usr.bin/tar/tar.h @@ -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. -- cgit v1.1