bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] Feature request with patch: prepending text to path


From: Andreas Kemnade
Subject: [Bug-tar] Feature request with patch: prepending text to path
Date: Mon, 8 May 2006 23:56:18 +0200

Hi,

I and some other people are interested in having the ability
to prepend text to the paths of files while creating a tar archive.

So you could do:

$ tar --prefix bar/ -f test.tar -c foo blubb
$ tar -tf test.tar 
bar/foo
bar/blubb


The patch is appended.

Greetings
Andreas Kemnade


Index: src/common.h
===================================================================
RCS file: /sources/tar/tar/src/common.h,v
retrieving revision 1.77
diff -u -r1.77 common.h
--- src/common.h        7 Feb 2006 20:55:50 -0000       1.77
+++ src/common.h        7 May 2006 20:53:09 -0000
@@ -296,6 +296,9 @@
 /* Output index file name.  */
 GLOBAL char const *index_file_name;
 
+/* prefix prepended to file paths when they are added */
+GLOBAL char *file_prefix;
+
 /* Structure for keeping track of filenames and lists thereof.  */
 struct name
   {
Index: src/create.c
===================================================================
RCS file: /sources/tar/tar/src/create.c,v
retrieving revision 1.113
diff -u -r1.113 create.c
--- src/create.c        20 Feb 2006 10:01:47 -0000      1.113
+++ src/create.c        7 May 2006 20:53:09 -0000
@@ -650,10 +650,20 @@
 {
   union block *header;
 
-  header = write_header_name (st);
-  if (!header)
+  if (file_prefix) {
+    struct tar_stat_info st2;
+    st2 = *st;
+    st2.file_name = malloc(strlen(st->file_name) + strlen(file_prefix) + 1);
+    strcpy(st2.file_name, file_prefix);
+    strcat(st2.file_name, st->file_name);
+    header = write_header_name (&st2);
+    free(st2.file_name);
+  } else {
+    header = write_header_name (st);
+  }
+  if (!header) {
     return NULL;
-
+  }
   /* Override some stat fields, if requested to do so.  */
 
   if (owner_option != (uid_t) -1)
Index: src/tar.c
===================================================================
RCS file: /sources/tar/tar/src/tar.c,v
retrieving revision 1.142
diff -u -r1.142 tar.c
--- src/tar.c   13 Mar 2006 09:42:55 -0000      1.142
+++ src/tar.c   7 May 2006 20:53:10 -0000
@@ -285,6 +285,7 @@
   OWNER_OPTION,
   PAX_OPTION,
   POSIX_OPTION,
+  PREFIX_OPTION,
   PRESERVE_OPTION,
   QUOTE_CHARS_OPTION,
   QUOTING_STYLE_OPTION,
@@ -547,6 +548,9 @@
 
   {"old-archive", OLD_ARCHIVE_OPTION, 0, 0, /* FIXME */
    N_("same as --format=v7"), GRID+8 },
+  {"prefix", PREFIX_OPTION, N_("PREFIX"), 0,
+   N_("prepend PREFIX"), GRID+8 },
+
   {"portability", 0, 0, OPTION_ALIAS, NULL, GRID+8 },
   {"posix", POSIX_OPTION, 0, 0,
    N_("same as --format=posix"), GRID+8 },
@@ -1413,6 +1417,11 @@
       same_order_option = true;
       break;
 
+   case PREFIX_OPTION:
+      file_prefix=strdup(arg);
+      break;
+
+
     case RECORD_SIZE_OPTION:
       {
        uintmax_t u;
@@ -2033,6 +2042,7 @@
 
   obstack_init (&argv_stk);
 
+  file_prefix = NULL;
 #ifdef SIGCHLD
   /* System V fork+wait does not work if SIGCHLD is ignored.  */
   signal (SIGCHLD, SIG_DFL);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]