Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

exclude.c File Reference

Go to the source code of this file.

Functions

exclude_structmake_exclude (const char *pattern, int include)
 Build an exclude structure given a exclude pattern. More...

void free_exclude (struct exclude_struct *ex)
int check_one_exclude (char *name, struct exclude_struct *ex, STRUCT_STAT *st)
void report_exclude_result (char const *name, struct exclude_struct const *ent, STRUCT_STAT const *st)
int check_exclude (char *name, struct exclude_struct **local_exclude_list, STRUCT_STAT *st)
void add_exclude_list (const char *pattern, struct exclude_struct ***list, int include)
void add_exclude (const char *pattern, int include)
exclude_struct ** make_exclude_list (const char *fname, struct exclude_struct **list1, int fatal, int include)
void add_exclude_file (const char *fname, int fatal, int include)
void send_exclude_list (int f)
void recv_exclude_list (int f)
char * get_exclude_tok (char *p)
void add_exclude_line (char *p)
void add_include_line (char *p)
void add_cvs_excludes (void)

Variables

int verbose
int delete_mode
exclude_struct ** exclude_list
char * cvs_ignore_list []


Function Documentation

struct exclude_struct* make_exclude const char *    pattern,
int    include
[static]
 

Build an exclude structure given a exclude pattern.

Definition at line 35 of file exclude.c.

References exclude_struct::directory, FERROR, fnmatch(), exclude_struct::fnmatch_flags, exclude_struct::include, exclude_struct::local, out_of_memory(), exclude_struct::pattern, exclude_struct::regular_exp, rprintf(), strdup(), and strpbrk().

Referenced by add_exclude_list().

00036 {
00037         struct exclude_struct *ret;
00038 
00039         ret = (struct exclude_struct *)malloc(sizeof(*ret));
00040         if (!ret) out_of_memory("make_exclude");
00041 
00042         memset(ret, 0, sizeof(*ret));
00043 
00044         if (strncmp(pattern,"- ",2) == 0) {
00045                 pattern += 2;
00046         } else if (strncmp(pattern,"+ ",2) == 0) {
00047                 ret->include = 1;
00048                 pattern += 2;
00049         } else {
00050                 ret->include = include;
00051         }
00052 
00053         ret->pattern = strdup(pattern);
00054 
00055         if (!ret->pattern) out_of_memory("make_exclude");
00056 
00057         if (strpbrk(pattern, "*[?")) {
00058             ret->regular_exp = 1;
00059             ret->fnmatch_flags = FNM_PATHNAME;
00060             if (strstr(pattern, "**")) {
00061                     static int tested;
00062                     if (!tested) {
00063                             tested = 1;
00064                             if (fnmatch("a/b/*", "a/b/c/d", FNM_PATHNAME)==0) {
00065                                     rprintf(FERROR,"WARNING: fnmatch FNM_PATHNAME is broken on your system\n");
00066                             }
00067                     }
00068                     ret->fnmatch_flags = 0;
00069             }
00070         }
00071 
00072         if (strlen(pattern) > 1 && pattern[strlen(pattern)-1] == '/') {
00073                 ret->pattern[strlen(pattern)-1] = 0;
00074                 ret->directory = 1;
00075         }
00076 
00077         if (!strchr(ret->pattern,'/')) {
00078                 ret->local = 1;
00079         }
00080 
00081         return ret;
00082 }

void free_exclude struct exclude_struct   ex [static]
 

Definition at line 84 of file exclude.c.

References exclude_struct::pattern.

Referenced by add_exclude_list().

00085 {
00086         free(ex->pattern);
00087         memset(ex,0,sizeof(*ex));
00088         free(ex);
00089 }

int check_one_exclude char *    name,
struct exclude_struct   ex,
STRUCT_STAT *    st
[static]
 

Definition at line 91 of file exclude.c.

References exclude_struct::directory, fnmatch(), exclude_struct::fnmatch_flags, exclude_struct::local, exclude_struct::pattern, and exclude_struct::regular_exp.

Referenced by check_exclude().

00093 {
00094         char *p;
00095         int match_start=0;
00096         char *pattern = ex->pattern;
00097 
00098         if (ex->local && (p=strrchr(name,'/')))
00099                 name = p+1;
00100 
00101         if (!name[0]) return 0;
00102 
00103         if (ex->directory && !S_ISDIR(st->st_mode)) return 0;
00104 
00105         if (*pattern == '/' && *name != '/') {
00106                 match_start = 1;
00107                 pattern++;
00108         }
00109 
00110         if (ex->regular_exp) {
00111                 if (fnmatch(pattern, name, ex->fnmatch_flags) == 0) {
00112                         return 1;
00113                 }
00114         } else {
00115                 int l1 = strlen(name);
00116                 int l2 = strlen(pattern);
00117                 if (l2 <= l1 && 
00118                     strcmp(name+(l1-l2),pattern) == 0 &&
00119                     (l1==l2 || (!match_start && name[l1-(l2+1)] == '/'))) {
00120                         return 1;
00121                 }
00122         }
00123 
00124         return 0;
00125 }

void report_exclude_result char const *    name,
struct exclude_struct const *    ent,
STRUCT_STAT const *    st
[static]
 

Definition at line 128 of file exclude.c.

References exclude_struct::directory, FINFO, exclude_struct::include, exclude_struct::pattern, rprintf(), and verbose.

Referenced by check_exclude().

00131 {
00132         /* If a trailing slash is present to match only directories,
00133          * then it is stripped out by make_exclude.  So as a special
00134          * case we add it back in here. */
00135         
00136         if (verbose >= 2)
00137                 rprintf(FINFO, "%s %s %s because of pattern %s%s\n",
00138                         ent->include ? "including" : "excluding",
00139                         S_ISDIR(st->st_mode) ? "directory" : "file",
00140                         name, ent->pattern,
00141                         ent->directory ? "/" : "");
00142 }

int check_exclude char *    name,
struct exclude_struct **    local_exclude_list,
STRUCT_STAT *    st
 

Definition at line 149 of file exclude.c.

References check_one_exclude(), exclude_struct::include, and report_exclude_result().

Referenced by check_exclude_file().

00151 {
00152         int n;
00153         struct exclude_struct *ent;
00154 
00155         if (name && (name[0] == '.') && !name[1])
00156                 /* never exclude '.', even if somebody does --exclude '*' */
00157                 return 0;
00158 
00159         if (exclude_list) {
00160                 for (n=0; exclude_list[n]; n++) {
00161                         ent = exclude_list[n];
00162                         if (check_one_exclude(name, ent, st)) {
00163                                 report_exclude_result(name, ent, st);
00164                                 return !ent->include;
00165                         }
00166                 }
00167         }
00168 
00169         if (local_exclude_list) {
00170                 for (n=0; local_exclude_list[n]; n++) {
00171                         ent = local_exclude_list[n];
00172                         if (check_one_exclude(name, ent, st)) {
00173                                 report_exclude_result(name, ent, st);
00174                                 return !ent->include;
00175                         }
00176                 }
00177         }
00178 
00179         return 0;
00180 }

void add_exclude_list const char *    pattern,
struct exclude_struct ***    list,
int    include
 

Definition at line 183 of file exclude.c.

References FINFO, free_exclude(), make_exclude(), out_of_memory(), rprintf(), and verbose.

Referenced by add_exclude(), make_exclude_list(), and send_directory().

00184 {
00185         int len=0;
00186         if (list && *list)
00187                 for (; (*list)[len]; len++) ;
00188 
00189         if (strcmp(pattern,"!") == 0) {
00190                 if (verbose > 2)
00191                         rprintf(FINFO,"clearing exclude list\n");
00192                 while ((len)--) {
00193                         free_exclude((*list)[len]);
00194                 }
00195                 free((*list));
00196                 *list = NULL;
00197                 return;
00198         }
00199 
00200         *list = (struct exclude_struct **)Realloc(*list,sizeof(struct exclude_struct *)*(len+2));
00201         
00202         if (!*list || !((*list)[len] = make_exclude(pattern, include)))
00203                 out_of_memory("add_exclude");
00204         
00205         if (verbose > 2) {
00206                 rprintf(FINFO,"add_exclude(%s,%s)\n",pattern,
00207                               include ? "include" : "exclude");
00208         }
00209 
00210         (*list)[len+1] = NULL;
00211 }

void add_exclude const char *    pattern,
int    include
 

Definition at line 213 of file exclude.c.

References add_exclude_list().

Referenced by add_cvs_excludes(), add_exclude_line(), add_include_line(), parse_arguments(), recv_exclude_list(), and send_exclude_list().

00214 {
00215         add_exclude_list(pattern,&exclude_list, include);
00216 }

struct exclude_struct** make_exclude_list const char *    fname,
struct exclude_struct **    list1,
int    fatal,
int    include
 

Definition at line 218 of file exclude.c.

References add_exclude_list(), FERROR, and rsyserr().

Referenced by add_exclude_file(), and send_directory().

00221 {
00222         struct exclude_struct **list=list1;
00223         FILE *f = fopen(fname,"r");
00224         char line[MAXPATHLEN];
00225         if (!f) {
00226                 if (fatal) {
00227                         rsyserr(FERROR, errno,
00228                                 "failed to open %s file %s",
00229                                 include ? "include" : "exclude",
00230                                 fname);
00231                         exit_cleanup(RERR_FILEIO);
00232                 }
00233                 return list;
00234         }
00235 
00236         while (fgets(line,MAXPATHLEN,f)) {
00237                 int l = strlen(line);
00238                 if (l && line[l-1] == '\n') l--;
00239                 line[l] = 0;
00240                 if (line[0] && (line[0] != ';') && (line[0] != '#')) {
00241                         /* Skip lines starting with semicolon or pound.
00242                            It probably wouldn't cause any harm to not skip
00243                              them but there's no need to save them. */
00244                         add_exclude_list(line,&list,include);
00245                 }
00246         }
00247         fclose(f);
00248         return list;
00249 }

void add_exclude_file const char *    fname,
int    fatal,
int    include
 

Definition at line 252 of file exclude.c.

References make_exclude_list().

Referenced by add_cvs_excludes(), parse_arguments(), and rsync_module().

00253 {
00254         if (!fname || !*fname) return;
00255 
00256         exclude_list = make_exclude_list(fname,exclude_list,fatal,include);
00257 }

void send_exclude_list int    f
 

Definition at line 260 of file exclude.c.

References add_exclude(), exclude_struct::directory, FERROR, exclude_struct::include, rprintf(), strlcat(), strlcpy(), write_buf(), and write_int().

Referenced by client_run().

00261 {
00262         int i;
00263         extern int remote_version;
00264         extern int list_only, recurse;
00265 
00266         /* This is a complete hack - blame Rusty.
00267          *
00268          * FIXME: This pattern shows up in the output of
00269          * report_exclude_result(), which is not ideal. */
00270         if (list_only && !recurse) {
00271                 add_exclude("/*/*", 0);
00272         }
00273 
00274         if (!exclude_list) {
00275                 write_int(f,0);
00276                 return;
00277         }
00278 
00279         for (i=0;exclude_list[i];i++) {
00280                 int l;
00281                 char pattern[MAXPATHLEN];
00282 
00283                 strlcpy(pattern,exclude_list[i]->pattern,sizeof(pattern)); 
00284                 if (exclude_list[i]->directory) strlcat(pattern,"/", sizeof(pattern));
00285 
00286                 l = strlen(pattern);
00287                 if (l == 0) continue;
00288                 if (exclude_list[i]->include) {
00289                         if (remote_version < 19) {
00290                                 rprintf(FERROR,"remote rsync does not support include syntax - aborting\n");
00291                                 exit_cleanup(RERR_UNSUPPORTED);
00292                         }
00293                         write_int(f,l+2);
00294                         write_buf(f,"+ ",2);
00295                 } else {
00296                         write_int(f,l);
00297                 }
00298                 write_buf(f,pattern,l);
00299         }    
00300 
00301         write_int(f,0);
00302 }

void recv_exclude_list int    f
 

Definition at line 305 of file exclude.c.

References add_exclude(), overflow(), read_int(), and read_sbuf().

Referenced by do_server_recv(), and start_server().

00306 {
00307         char line[MAXPATHLEN];
00308         unsigned int l;
00309 
00310         while ((l=read_int(f))) {
00311                 if (l >= MAXPATHLEN) overflow("recv_exclude_list");
00312                 read_sbuf(f,line,l);
00313                 add_exclude(line,0);
00314         }
00315 }

char* get_exclude_tok char *    p
 

Definition at line 322 of file exclude.c.

Referenced by add_exclude_line(), and add_include_line().

00323 {
00324         static char *s;
00325         static int more;
00326         char *t;
00327 
00328         if (p) {
00329                 s=p;
00330                 if (*p)
00331                         more=1;
00332         }
00333 
00334         if (!more)
00335                 return(NULL);
00336 
00337         /* Skip over any initial spaces */
00338         while (isspace(* (unsigned char *) s))
00339                 s++;
00340 
00341         /* Are we at the end of the string? */
00342         if (*s) {
00343                 /* remember the beginning of the token */
00344                 t=s;
00345 
00346                 /* Is this a '+' or '-' followed by a space (not whitespace)? */
00347                 if ((*s=='+' || *s=='-') && *(s+1)==' ')
00348                         s+=2;
00349         
00350                 /* Skip to the next space or the end of the string */
00351                 while (!isspace(* (unsigned char *) s) && *s != '\0')
00352                         s++;
00353         } else {
00354                 t=NULL;
00355         }
00356 
00357         /* Have we reached the end of the string? */
00358         if (*s)
00359                 *s++='\0';
00360         else
00361                 more=0;
00362         return(t);
00363 }

void add_exclude_line char *    p
 

Definition at line 366 of file exclude.c.

References add_exclude(), get_exclude_tok(), out_of_memory(), and strdup().

Referenced by add_cvs_excludes(), and rsync_module().

00367 {
00368         char *tok;
00369         if (!p || !*p) return;
00370         p = strdup(p);
00371         if (!p) out_of_memory("add_exclude_line");
00372         for (tok=get_exclude_tok(p); tok; tok=get_exclude_tok(NULL))
00373                 add_exclude(tok, 0);
00374         free(p);
00375 }

void add_include_line char *    p
 

Definition at line 377 of file exclude.c.

References add_exclude(), get_exclude_tok(), out_of_memory(), and strdup().

Referenced by rsync_module().

00378 {
00379         char *tok;
00380         if (!p || !*p) return;
00381         p = strdup(p);
00382         if (!p) out_of_memory("add_include_line");
00383         for (tok=get_exclude_tok(p); tok; tok=get_exclude_tok(NULL))
00384                 add_exclude(tok, 1);
00385         free(p);
00386 }

void add_cvs_excludes void   
 

Definition at line 398 of file exclude.c.

References add_exclude(), add_exclude_file(), add_exclude_line(), cvs_ignore_list, getenv(), and snprintf().

Referenced by client_run(), delete_files(), and start_server().

00399 {
00400         char fname[MAXPATHLEN];
00401         char *p;
00402         int i;
00403   
00404         for (i=0; cvs_ignore_list[i]; i++)
00405                 add_exclude(cvs_ignore_list[i], 0);
00406 
00407         if ((p=getenv("HOME")) && strlen(p) < (MAXPATHLEN-12)) {
00408                 snprintf(fname,sizeof(fname), "%s/.cvsignore",p);
00409                 add_exclude_file(fname,0,0);
00410         }
00411 
00412         add_exclude_line(getenv("CVSIGNORE"));
00413 }


Variable Documentation

int verbose
 

Definition at line 29 of file exclude.c.

Referenced by add_exclude_list(), and report_exclude_result().

int delete_mode
 

Definition at line 30 of file exclude.c.

struct exclude_struct** exclude_list [static]
 

Definition at line 32 of file exclude.c.

char* cvs_ignore_list[] [static]
 

Initial value:

 {
  "RCS","SCCS","CVS","CVS.adm","RCSLOG","cvslog.*",
  "tags","TAGS",".make.state",".nse_depinfo",
  "*~", "#*", ".#*", ",*", "*.old", "*.bak", "*.BAK", "*.orig",
  "*.rej", ".del-*", "*.a", "*.o", "*.obj", "*.so", "*.Z", "*.elc", "*.ln",
  "core",NULL}

Definition at line 389 of file exclude.c.

Referenced by add_cvs_excludes().


Generated on Tue Apr 16 12:37:38 2002 for rsync by doxygen1.2.15