From 4cee66d5a8a49f6bd6342923aff94262812fba73 Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Thu, 28 Aug 2003 19:12:23 +0000 Subject: Dont unlink when testing ! Always preserve creation date Disable the -p option its for modification date Remove some cpio header debugging noise Syncronise file listing behaviour with upstream. --- archival/libunarchive/data_extract_all.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'archival/libunarchive/data_extract_all.c') diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c index c6ace2c33..05bd2f03b 100644 --- a/archival/libunarchive/data_extract_all.c +++ b/archival/libunarchive/data_extract_all.c @@ -39,6 +39,31 @@ extern void data_extract_all(archive_handle_t *archive_handle) free(name); } + /* Check if the file already exists */ + if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) { + /* Remove the existing entry if it exists */ + if ((unlink(file_header->name) == -1) && (errno != ENOENT)) { + bb_perror_msg_and_die("Couldnt remove old file"); + } + } + else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) { + /* Remove the existing entry if its older than the extracted entry */ + struct stat statbuf; + if ((lstat(file_header->name, &statbuf) == -1) && (errno != ENOENT)) { + bb_perror_msg_and_die("Couldnt stat old file"); + } + if (statbuf.st_mtime <= file_header->mtime) { + if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { + bb_error_msg("%s not created: newer or same age file exists", file_header->name); + } + data_skip(archive_handle); + return; + } + if ((unlink(file_header->name) == -1) && (errno != ENOENT)) { + bb_perror_msg_and_die("Couldnt remove old file"); + } + } + /* Handle hard links seperately */ if (!S_ISLNK(file_header->mode) && (file_header->link_name) && (file_header->size == 0)) { /* hard link */ -- cgit v1.2.3