OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
tar-patch

From: Steffen Wendzel (SWendzelt-online.de)
Date: Sun Jul 03 2005 - 06:39:05 CDT


Hi.

I ported a feature from Solaris' 'tar' to OpenBSD's 'tar' tool.
It is the -X parameter to exclude files from an archive. OpenBSD's
tar already got an -X parameter, so i gave it the name -E (for exclude).
This parameter takes an regular expression:

cdp_xeeygo:/tmp$ tar -cvz -E ^pp$ -E y$ -f pp.tgz p*
excluding: pp
excluding: pp.y
pp.c
cdp_xeeygo:/tmp$ tar -xzvf pp.tgz
pp.c

This is the patch:

------------------------- snip ---------------------
--- ../pax_backup/ar_io.c Sat Jul 2 21:18:34 2005
+++ ar_io.c Sun Jul 3 13:16:02 2005
-83,6 +83,8
 static int wr_trail = 1; /* trailer was rewritten in append */
 static int can_unlnk = 0; /* do we unlink null archives? */
 const char *arcname; /* printable name of archive */
+int exclude_count = 0; /* list of regex-strings for exclude */
+regex_t **exclude; /* files tar should not add to archive */
 const char *gzip_program; /* name of gzip program */
 static pid_t zpid = -1; /* pid of child process */
 int force_one_volume; /* 1 if we ignore volume changes */
--- ../pax_backup/ftree.c Sat Jul 2 21:18:34 2005
+++ ftree.c Sun Jul 3 13:23:58 2005
-147,6 +147,7
 {
         FTREE *ft;
         int len;
+ int excl_tmp;
 
         /*
          * simple check for bad args
-155,6 +156,12
                 paxwarn(0, "Invalid file name argument");
                 return(-1);
         }
+
+ for(excl_tmp=0; excl_tmp < exclude_count; excl_tmp++)
+ if(regexec(exclude[excl_tmp], str, 0, NULL, 0)==0) {
+ printf("excluding: %s\n", str);
+ return(0);
+ }
 
         /*
          * allocate FTREE node and add to the end of the linked list (args are
--- ../pax_backup/options.c Sat Jul 2 21:18:34 2005
+++ options.c Sun Jul 3 13:25:16 2005
-616,7 +616,7
          * process option flags
          */
         while ((c = getoldopt(argc, argv,
- "b:cef:hmopqruts:vwxzBC:HI:LOPXZ014578")) != -1) {
+ "b:cef:hmopqruts:vwxzBC:E:HI:LOPXZ014578")) != -1) {
                 switch (c) {
                 case 'b':
                         /*
-742,6 +742,21
                 case 'C':
                         chdname = optarg;
                         break;
+ case 'E':
+ if((exclude = (regex_t **) realloc(exclude, (sizeof(regex_t *)*(exclude_count+1))))==NULL) {
+ perror("realloc");
+ exit(1);
+ }
+ if((exclude[exclude_count] = (regex_t *) malloc(sizeof(regex_t *)))==NULL) {
+ perror("malloc");
+ exit(1);
+ }
+ if(regcomp(exclude[exclude_count], optarg, 0)!=0) {
+ perror("regcomp");
+ exit(1);
+ }
+ exclude_count++;
+ break;
                 case 'H':
                         /*
                          * follow command line symlinks only
-1551,11 +1566,12
 tar_usage(void)
 {
         (void)fputs(
- "usage: tar {crtux}[014578befHhLmOoPpqsvwXZz]\n"
- "\t [blocking-factor | archive | replstr] [-C directory] [-I file]\n"
- "\t [file ...]\n"
+ "usage: tar {crtux}[014578bEefHhLmOoPpqsvwXZz]\n"
+ "\t [blocking-factor | archive | replstr] [-C directory] [-E regex]\n"
+ "\t [-I file] [file ...]\n"
             " tar {-crtux} [-014578eHhLmOoPpqvwXZz] [-b blocking-factor]\n"
- "\t [-C directory] [-f archive] [-I file] [-s replstr] [file ...]\n",
+ "\t [-C directory] [-f archive] [-E regex] [-I file] [-s replstr]\n"
+ "\t [file ...]\n",
             stderr);
         exit(1);
 }
--- ../pax_backup/extern.h Sat Jul 2 21:18:34 2005
+++ extern.h Sun Jul 3 13:15:58 2005
-41,10 +41,13
  */
 
 #include <sys/cdefs.h>
+#include <regex.h>
 
 /*
  * ar_io.c
  */
+extern int exclude_count;
+extern regex_t **exclude;
 extern const char *arcname;
 extern const char *gzip_program;
 extern int force_one_volume;
--- ../pax_backup/tar.1 Sat Jul 2 21:18:34 2005
+++ tar.1 Sun Jul 3 13:29:49 2005
-141,6 +141,9
 When extracting, files will be extracted into
 the specified directory; when creating, the specified files will be matched
 from the directory.
+.It Fl E
+Exclude a file given throught a regular expression. You can use this option
+multiple times in one command.
 .It Fl e
 Stop after the first error.
 .It Fl f Ar archive

------------------------- snap ---------------------

--
www.wendzel.de

[demime 1.01d removed an attachment of type application/octet-stream which had a name of tar_patch]