Blame SOURCES/tar-1.26-keep-directory-symlink.patch

0c9d7d
From c4a4cafaa330793d776b001c272bf19869aac39c Mon Sep 17 00:00:00 2001
0c9d7d
From: Sergey Poznyakoff <gray@gnu.org.ua>
0c9d7d
Date: Mon, 23 Sep 2013 19:35:29 +0300
0c9d7d
Subject: [PATCH] Changes for compatibility with Slackware installation
0c9d7d
 scripts.
0c9d7d
0c9d7d
* src/buffer.c (short_read): the "Record size" message
0c9d7d
is controlled by the WARN_RECORD_SIZE warning_option bit.
0c9d7d
* src/common.h (keep_directory_symlink_option): New global.
0c9d7d
(WARN_RECORD_SIZE): New constant.
0c9d7d
(WARN_VERBOSE_WARNINGS): Add WARN_RECORD_SIZE.
0c9d7d
* src/extract.c (extract_dir): If keep_directory_symlink_option is
0c9d7d
set, follow symlinks to directories.
0c9d7d
* src/suffix.c (compression_suffixes): Add support for txz
0c9d7d
suffix.
0c9d7d
* src/tar.c (KEEP_DIRECTORY_SYMLINK_OPTION): New constant.
0c9d7d
(options): New option --keep-directory-symlink.
0c9d7d
(parse_opt): Handle this option.
0c9d7d
* src/warning.c: Implement "record-size" warning control.
0c9d7d
0c9d7d
* NEWS: Update.
0c9d7d
* doc/tar.texi: Document new features.
0c9d7d
---
0c9d7d
 NEWS          | 12 ++++++++++++
0c9d7d
 doc/tar.texi  | 15 +++++++++++++++
0c9d7d
 src/common.h  |  2 ++
0c9d7d
 src/extract.c | 19 +++++++++++++++++++
0c9d7d
 src/tar.c     |  8 ++++++++
0c9d7d
 5 files changed, 56 insertions(+)
0c9d7d
0c9d7d
diff --git a/NEWS b/NEWS
0c9d7d
index 8f3c416..36a27da 100644
0c9d7d
--- a/NEWS
0c9d7d
+++ b/NEWS
0c9d7d
@@ -6,6 +6,18 @@ Please send GNU tar bug reports to <bug-tar@gnu.org>
0c9d7d
 When creating a PAX-format archive, tar no longer arbitrarily restricts
0c9d7d
 the size of the representation of a sparse file to be less than 8 GiB.
0c9d7d
 
0c9d7d
+* New command line option --keep-directory-symlink
0c9d7d
+
0c9d7d
+By default, if when trying to extract a directory from the archive,
0c9d7d
+tar discovers that the corresponding file name already exists and is a
0c9d7d
+symbolic link, it first unlinks the entry, and then extracts the directory.
0c9d7d
+
0c9d7d
+This option disables this behavior and instructs tar to follow
0c9d7d
+symlinks to directories when extracting from the archive.
0c9d7d
+
0c9d7d
+It is mainly intended to provide compatibility with the Slackware
0c9d7d
+installation scripts.
0c9d7d
+
0c9d7d
 
0c9d7d
 version 1.26 - Sergey Poznyakoff, 2011-03-12
0c9d7d
 
0c9d7d
diff --git a/doc/tar.texi b/doc/tar.texi
0c9d7d
index 6bd59c7..fb03b85 100644
0c9d7d
--- a/doc/tar.texi
0c9d7d
+++ b/doc/tar.texi
0c9d7d
@@ -2923,6 +2923,21 @@ Specifies that @command{tar} should ask the user for confirmation before
0c9d7d
 performing potentially destructive options, such as overwriting files.
0c9d7d
 @xref{interactive}.
0c9d7d
 
0c9d7d
+@opsummary{--keep-directory-symlink}
0c9d7d
+@item --keep-directory-symlink
0c9d7d
+
0c9d7d
+This option changes the behavior of tar when it encounters a symlink
0c9d7d
+with the same name as the directory that it is about to extract.  By
0c9d7d
+default, in this case tar would first remove the symlink and then
0c9d7d
+proceed extracting the directory.
0c9d7d
+
0c9d7d
+The @option{--keep-directory-symlink} option disables this behavior
0c9d7d
+and instructs tar to follow symlinks to directories when extracting
0c9d7d
+from the archive.
0c9d7d
+
0c9d7d
+It is mainly intended to provide compatibility with the Slackware
0c9d7d
+installation scripts.
0c9d7d
+
0c9d7d
 @opsummary{keep-newer-files}
0c9d7d
 @item --keep-newer-files
0c9d7d
 
0c9d7d
diff --git a/src/common.h b/src/common.h
0c9d7d
index 16ba401..274da01 100644
0c9d7d
--- a/src/common.h
0c9d7d
+++ b/src/common.h
0c9d7d
@@ -192,6 +192,8 @@ enum old_files
0c9d7d
 };
0c9d7d
 GLOBAL enum old_files old_files_option;
0c9d7d
 
0c9d7d
+GLOBAL bool keep_directory_symlink_option;
0c9d7d
+
0c9d7d
 /* Specified file name for incremental list.  */
0c9d7d
 GLOBAL const char *listed_incremental_option;
0c9d7d
 /* Incremental dump level */
0c9d7d
diff --git a/src/extract.c b/src/extract.c
0c9d7d
index 3afb95d..b622a2a 100644
0c9d7d
--- a/src/extract.c
0c9d7d
+++ b/src/extract.c
0c9d7d
@@ -854,7 +854,21 @@ apply_nonancestor_delayed_set_stat (char const *file_name, bool after_links)
0c9d7d
 }
0c9d7d
 
0c9d7d
 
0c9d7d
+static bool
0c9d7d
+is_directory_link (const char *file_name)
0c9d7d
+{
0c9d7d
+  struct stat st;
0c9d7d
+  int e = errno;
0c9d7d
+  int res;
0c9d7d
 
0c9d7d
+  res = (fstatat (chdir_fd, file_name, &st, AT_SYMLINK_NOFOLLOW) == 0 &&
0c9d7d
+	 S_ISLNK (st.st_mode) &&
0c9d7d
+	 fstatat (chdir_fd, file_name, &st, 0) == 0 &&
0c9d7d
+	 S_ISDIR (st.st_mode));
0c9d7d
+  errno = e;
0c9d7d
+  return res;
0c9d7d
+}
0c9d7d
+
0c9d7d
 /* Extractor functions for various member types */
0c9d7d
 
0c9d7d
 static int
0c9d7d
@@ -910,10 +924,15 @@ extract_dir (char *file_name, int typeflag)
0c9d7d
 
0c9d7d
       if (errno == EEXIST
0c9d7d
 	  && (interdir_made
0c9d7d
+	      || keep_directory_symlink_option
0c9d7d
 	      || old_files_option == DEFAULT_OLD_FILES
0c9d7d
 	      || old_files_option == OVERWRITE_OLD_FILES))
0c9d7d
 	{
0c9d7d
 	  struct stat st;
0c9d7d
+
0c9d7d
+	  if (keep_directory_symlink_option && is_directory_link (file_name))
0c9d7d
+	    return 0;
0c9d7d
+
0c9d7d
 	  if (deref_stat (file_name, &st) == 0)
0c9d7d
 	    {
0c9d7d
 	      current_mode = st.st_mode;
0c9d7d
diff --git a/src/tar.c b/src/tar.c
0c9d7d
index 18277e4..d62ca0e 100644
0c9d7d
--- a/src/tar.c
0c9d7d
+++ b/src/tar.c
0c9d7d
@@ -290,6 +290,7 @@ enum
0c9d7d
   IGNORE_COMMAND_ERROR_OPTION,
0c9d7d
   IGNORE_FAILED_READ_OPTION,
0c9d7d
   INDEX_FILE_OPTION,
0c9d7d
+  KEEP_DIRECTORY_SYMLINK_OPTION,
0c9d7d
   KEEP_NEWER_FILES_OPTION,
0c9d7d
   LEVEL_OPTION,
0c9d7d
   LZIP_OPTION,
0c9d7d
@@ -488,6 +489,9 @@ static struct argp_option options[] = {
0c9d7d
   {"overwrite-dir", OVERWRITE_DIR_OPTION, 0, 0,
0c9d7d
    N_("overwrite metadata of existing directories when extracting (default)"),
0c9d7d
    GRID+1 },
0c9d7d
+  {"keep-directory-symlink", KEEP_DIRECTORY_SYMLINK_OPTION, 0, 0,
0c9d7d
+   N_("preserve existing symlinks to directories when extracting"),
0c9d7d
+   GRID+1 },
0c9d7d
 #undef GRID
0c9d7d
 
0c9d7d
 #define GRID 40
0c9d7d
@@ -1878,6 +1882,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
0c9d7d
       ignore_failed_read_option = true;
0c9d7d
       break;
0c9d7d
 
0c9d7d
+    case KEEP_DIRECTORY_SYMLINK_OPTION:
0c9d7d
+      keep_directory_symlink_option = true;
0c9d7d
+      break;
0c9d7d
+
0c9d7d
     case KEEP_NEWER_FILES_OPTION:
0c9d7d
       old_files_option = KEEP_NEWER_FILES;
0c9d7d
       break;
0c9d7d
-- 
0c9d7d
2.9.3
0c9d7d