From 847bf0fdc9b7822157bcc1b36b6570e2ad05bb14 Mon Sep 17 00:00:00 2001 From: kientzle Date: Tue, 13 Mar 2007 06:04:24 +0000 Subject: When ARCHIVE_EXTRACT_UNLINK is requested: * Only try to remove the existing item if we're not restoring a directory. * If unlink fails, try rmdir next. This should fix the broken --unlink option in bsdtar. Thanks again to: Kris Kennaway, for beating up bsdtar on pointyhat. --- lib/libarchive/Makefile | 2 +- lib/libarchive/archive_write_disk.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile index a3f35b1..e66d374 100644 --- a/lib/libarchive/Makefile +++ b/lib/libarchive/Makefile @@ -9,7 +9,7 @@ LDADD= -lbz2 -lz # Major: Bumped ONLY when API/ABI breakage happens (see SHLIB_MAJOR) # Minor: Bumped when significant new features are added # Revision: Bumped on any notable change -VERSION= 2.0.23 +VERSION= 2.0.24 ARCHIVE_API_MAJOR!= echo ${VERSION} | sed -e 's/[^0-9]/./g' -e 's/\..*//' ARCHIVE_API_MINOR!= echo ${VERSION} | sed -e 's/[^0-9]/./g' -e 's/[0-9]*\.//' -e 's/\..*//' diff --git a/lib/libarchive/archive_write_disk.c b/lib/libarchive/archive_write_disk.c index 1f8f0ce..02fabd6 100644 --- a/lib/libarchive/archive_write_disk.c +++ b/lib/libarchive/archive_write_disk.c @@ -659,14 +659,20 @@ restore_entry(struct archive_write_disk *a) { int ret = ARCHIVE_OK, en; - if (a->flags & ARCHIVE_EXTRACT_UNLINK) - if (unlink(a->name) != 0 && errno != ENOENT) { - /* If the file doesn't exist, that's okay. */ - /* Anything else is a problem. */ + if (a->flags & ARCHIVE_EXTRACT_UNLINK && !S_ISDIR(a->mode)) { + if (unlink(a->name) == 0) { + /* We removed it, we're done. */ + } else if (errno == ENOENT) { + /* File didn't exist, that's just as good. */ + } else if (rmdir(a->name) == 0) { + /* It was a dir, but now it's gone. */ + } else { + /* We tried, but couldn't get rid of it. */ archive_set_error(&a->archive, errno, "Could not unlink"); return(ARCHIVE_WARN); } + } /* Try creating it first; if this fails, we'll try to recover. */ en = create_filesystem_object(a); -- cgit v1.1