|
From: Wes C. <wes...@us...> - 2006-02-17 20:30:14
|
Update of /cvsroot/radmind/radmind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3644 Modified Files: applefile.h cksum.c fsdiff.c radstat.c stor.c transcript.c transcript.h Log Message: first pass at improving speed of fsdiff without checksums Index: transcript.h =================================================================== RCS file: /cvsroot/radmind/radmind/transcript.h,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** transcript.h 3 Oct 2005 15:57:13 -0000 1.39 --- transcript.h 17 Feb 2006 20:30:01 -0000 1.40 *************** *** 59,63 **** }; ! int transcript( char * ); void transcript_init( char *kfile, int location ); struct transcript *transcript_select( void ); --- 59,63 ---- }; ! int transcript( char *, struct stat *, char *, struct applefileinfo * ); void transcript_init( char *kfile, int location ); struct transcript *transcript_select( void ); Index: cksum.c =================================================================== RCS file: /cvsroot/radmind/radmind/cksum.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** cksum.c 3 Oct 2005 17:02:21 -0000 1.16 --- cksum.c 17 Feb 2006 20:30:01 -0000 1.17 *************** *** 97,101 **** { int dfd, rfd, rc; ! char buf[ 8192 ]; off_t size = 0; extern struct as_header as_header; --- 97,101 ---- { int dfd, rfd, rc; ! char buf[ 8192 ], rsrc_path[ MAXPATHLEN ]; off_t size = 0; extern struct as_header as_header; *************** *** 122,126 **** /* checksum rsrc fork data */ if ( afinfo->as_ents[ AS_RFE ].ae_length > 0 ) { ! if (( rfd = open( afinfo->rsrc_path, O_RDONLY )) < 0 ) { return( -1 ); } --- 122,132 ---- /* checksum rsrc fork data */ if ( afinfo->as_ents[ AS_RFE ].ae_length > 0 ) { ! if ( snprintf( rsrc_path, MAXPATHLEN, "%s%s", ! path, _PATH_RSRCFORKSPEC ) >= MAXPATHLEN ) { ! errno = ENAMETOOLONG; ! return( -1 ); ! } ! ! if (( rfd = open( rsrc_path, O_RDONLY )) < 0 ) { return( -1 ); } Index: applefile.h =================================================================== RCS file: /cvsroot/radmind/radmind/applefile.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** applefile.h 20 Sep 2004 21:22:28 -0000 1.19 --- applefile.h 17 Feb 2006 20:30:01 -0000 1.20 *************** *** 64,70 **** struct applefileinfo { - #ifdef __APPLE__ - char rsrc_path[ MAXPATHLEN ]; - #endif /* __APPLE__ */ struct attr_info ai; // finder info struct as_entry as_ents[ 3 ]; // Apple Single entries --- 64,67 ---- Index: transcript.c =================================================================== RCS file: /cvsroot/radmind/radmind/transcript.c,v retrieving revision 1.113 retrieving revision 1.114 diff -C2 -d -r1.113 -r1.114 *** transcript.c 8 Oct 2005 21:32:33 -0000 1.113 --- transcript.c 17 Feb 2006 20:30:01 -0000 1.114 *************** *** 23,27 **** #include "argcargv.h" #include "code.h" - #include "radstat.h" #include "cksum.h" #include "pathcmp.h" --- 23,26 ---- *************** *** 611,615 **** int ! transcript( char *path ) { struct pathinfo pi; --- 610,614 ---- int ! transcript( char *path, struct stat *st, char *type, struct applefileinfo *afinfo ) { struct pathinfo pi; *************** *** 625,647 **** */ if ( path != NULL ) { - switch ( radstat( path, &pi.pi_stat, &pi.pi_type, - &pi.pi_afinfo )) { - case 0: - break; - case 1: - fprintf( stderr, "%s is of an unknown type\n", path ); - exit( 2 ); - default: - if (( errno == ENOTDIR ) || ( errno == ENOENT )) { - memset( &pi.pi_stat, 0, sizeof( struct stat )); - pi.pi_type = 'X'; - break; - } else { - perror( path ); - exit( 2 ); - } - } - strcpy( pi.pi_name, path ); /* if it's multiply referenced, check if it's a hardlink */ --- 624,631 ---- */ if ( path != NULL ) { strcpy( pi.pi_name, path ); + pi.pi_stat = *st; + pi.pi_type = *type; + pi.pi_afinfo = *afinfo; /* if it's multiply referenced, check if it's a hardlink */ *************** *** 936,940 **** * filesystem to compare against. */ ! transcript( NULL ); while ( tran_head != NULL ) { --- 920,924 ---- * filesystem to compare against. */ ! transcript( NULL, NULL, NULL, NULL ); while ( tran_head != NULL ) { Index: radstat.c =================================================================== RCS file: /cvsroot/radmind/radmind/radstat.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** radstat.c 9 Nov 2004 20:33:27 -0000 1.25 --- radstat.c 17 Feb 2006 20:30:01 -0000 1.26 *************** *** 38,41 **** --- 38,45 ---- if ( lstat( path, st ) != 0 ) { + if (( errno == ENOTDIR ) || ( errno == ENOENT )) { + memset( st, 0, sizeof( struct stat )); + *type = 'X'; + } return( -1 ); } *************** *** 103,112 **** /* Calculate full size of applefile */ if ( *type == 'a' ) { - - if ( snprintf( afinfo->rsrc_path, MAXPATHLEN, - "%s%s", path, _PATH_RSRCFORKSPEC ) > MAXPATHLEN - 1 ) { - errno = ENAMETOOLONG; - return( -1 ); - } /* Finder Info */ --- 107,110 ---- Index: fsdiff.c =================================================================== RCS file: /cvsroot/radmind/radmind/fsdiff.c,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** fsdiff.c 5 Oct 2005 14:53:00 -0000 1.75 --- fsdiff.c 17 Feb 2006 20:30:01 -0000 1.76 *************** *** 6,11 **** #include "config.h" - #include <sys/types.h> #include <sys/param.h> #include <unistd.h> #include <errno.h> --- 6,12 ---- #include "config.h" #include <sys/param.h> + #include <sys/types.h> + #include <sys/stat.h> #include <unistd.h> #include <errno.h> *************** *** 13,16 **** --- 14,18 ---- #include <stdio.h> #include <string.h> + #include <fcntl.h> #include <openssl/evp.h> *************** *** 18,23 **** #include "applefile.h" #include "transcript.h" - #include "llist.h" #include "pathcmp.h" void (*logger)( char * ) = NULL; --- 20,25 ---- #include "applefile.h" #include "transcript.h" #include "pathcmp.h" + #include "radstat.h" void (*logger)( char * ) = NULL; *************** *** 25,42 **** extern char *version, *checksumlist; ! void fs_walk( char *, int, int ); int dodots = 0; int lastpercent = -1; int case_sensitive = 1; const EVP_MD *md; void ! fs_walk( char *path, int start, int finish ) { DIR *dir; struct dirent *de; ! struct llist *head = NULL; ! struct llist *new; ! struct llist *cur; int len; int count = 0; --- 27,88 ---- extern char *version, *checksumlist; ! void fs_walk( char *, struct stat *, char *, struct applefileinfo *, ! int, int ); int dodots = 0; + int dotfd; int lastpercent = -1; int case_sensitive = 1; const EVP_MD *md; + static struct fs_list *fs_insert( struct fs_list **, struct fs_list *, + char *, int (*)( char *, char * )); + + struct fs_list { + struct fs_list *fl_next; + char *fl_name; + struct stat fl_stat; + char fl_type; + struct applefileinfo fl_afinfo; + }; + + static struct fs_list * + fs_insert( struct fs_list **head, struct fs_list *last, + char *name, int (*cmp)( char *, char * )) + { + struct fs_list **current, *new; + + if (( last != NULL ) && ( (*cmp)( name, last->fl_name ) > 0 )) { + current = &last->fl_next; + } else { + current = head; + } + + /* find where in the list to put the new entry */ + for ( ; *current != NULL; current = &(*current)->fl_next) { + if ( (*cmp)( name, (*current)->fl_name ) <= 0 ) { + break; + } + } + + if (( new = malloc( sizeof( struct fs_list ))) == NULL ) { + return( NULL ); + } + if (( new->fl_name = strdup( name )) == NULL ) { + free( new ); + return( NULL ); + } + + new->fl_next = *current; + *current = new; + return( new ); + } + void ! fs_walk( char *path, struct stat *st, char *type, struct applefileinfo *afinfo, ! int start, int finish ) { DIR *dir; struct dirent *de; ! struct fs_list *head = NULL, *cur, *new = NULL, *next; int len; int count = 0; *************** *** 44,47 **** --- 90,94 ---- char temp[ MAXPATHLEN ]; struct transcript *tran; + int (*cmp)( char *, char * ); if (( finish > 0 ) && ( start != lastpercent )) { *************** *** 52,56 **** /* call the transcript code */ ! switch ( transcript( path )) { case 2 : /* negative directory */ for (;;) { --- 99,103 ---- /* call the transcript code */ ! switch ( transcript( path, st, type, afinfo )) { case 2 : /* negative directory */ for (;;) { *************** *** 61,72 **** if ( ischildcase( tran->t_pinfo.pi_name, path, case_sensitive )) { ! /* ! * XXX ! * This strcpy() is not itself dangerous, because pi_name ! * is a MAXPATHLEN-sized buffer. However, it does not appear ! * that copies into pi_name are carefully checked. ! */ strcpy( temp, tran->t_pinfo.pi_name ); ! fs_walk( temp, start, finish ); } else { return; --- 108,130 ---- if ( ischildcase( tran->t_pinfo.pi_name, path, case_sensitive )) { ! struct stat st0; ! char type0; ! struct applefileinfo afinfo0; ! strcpy( temp, tran->t_pinfo.pi_name ); ! switch ( radstat( temp, &st0, &type0, &afinfo0 ) < 0 ) { ! case 0: ! break; ! case 1: ! fprintf( stderr, "%s is of an unknown type\n", temp ); ! exit( 2 ); ! default: ! if (( errno != ENOTDIR ) && ( errno != ENOENT )) { ! perror( path ); ! exit( 2 ); ! } ! } ! ! fs_walk( temp, &st0, &type0, &afinfo0, start, finish ); } else { return; *************** *** 86,91 **** } /* open directory */ ! if (( dir = opendir( path )) == NULL ) { perror( path ); exit( 2 ); --- 144,160 ---- } + if ( case_sensitive ) { + cmp = strcmp; + } else { + cmp = strcasecmp; + } + + if ( chdir( path ) < 0 ) { + perror( path ); + exit( 2 ); + } + /* open directory */ ! if (( dir = opendir( "." )) == NULL ) { perror( path ); exit( 2 ); *************** *** 102,152 **** count++; - len = strlen( path ); ! /* absolute pathname. add 2 for / and NULL termination. */ ! if (( len + strlen( de->d_name ) + 2 ) > MAXPATHLEN ) { ! fprintf( stderr, "Absolute pathname too long\n" ); exit( 2 ); } if ( path[ len - 1 ] == '/' ) { ! if ( snprintf( temp, MAXPATHLEN, "%s%s", path, de->d_name ) >= MAXPATHLEN ) { ! fprintf( stderr, "%s%s: path too long\n", path, de->d_name ); exit( 2 ); } } else { ! if ( snprintf( temp, MAXPATHLEN, "%s/%s", path, de->d_name ) >= MAXPATHLEN ) { ! fprintf( stderr, "%s/%s: path too long\n", path, de->d_name ); exit( 2 ); } } ! /* allocate new node for newly created relative pathname */ ! new = ll_allocate( temp ); ! ! /* insert new file into the list */ ! if ( case_sensitive ) { ! ll_insert( &head, new ); ! } else { ! ll_insert_case( &head, new ); ! } ! } ! ! chunk = (( finish - start ) / ( float )count ); ! ! if ( closedir( dir ) != 0 ) { ! perror( "closedir" ); ! exit( 2 ); ! } - /* call fswalk on each element in the sorted list */ - for ( cur = head; cur != NULL; cur = cur->ll_next ) { - fs_walk( cur->ll_name, ( int )f, ( int )( f + chunk )); f += chunk; - } ! ll_free( head ); return; --- 171,234 ---- count++; ! if (( new = fs_insert( &head, new, de->d_name, cmp )) == NULL ) { ! perror( "malloc" ); ! exit( 1 ); ! } ! ! switch ( radstat( new->fl_name, &new->fl_stat, &new->fl_type, ! &new->fl_afinfo ) < 0 ) { ! case 0: ! break; ! case 1: ! fprintf( stderr, "%s is of an unknown type\n", path ); exit( 2 ); + default: + if (( errno != ENOTDIR ) && ( errno != ENOENT )) { + perror( path ); + exit( 2 ); + } } + } + + if ( closedir( dir ) != 0 ) { + perror( "closedir" ); + exit( 2 ); + } + if ( fchdir( dotfd ) < 0 ) { + perror( "OOPS!" ); + exit( 2 ); + } + + chunk = (( finish - start ) / ( float )count ); + + len = strlen( path ); + + /* call fswalk on each element in the sorted list */ + for ( cur = head; cur != NULL; cur = next ) { if ( path[ len - 1 ] == '/' ) { ! if ( snprintf( temp, MAXPATHLEN, "%s%s", path, cur->fl_name ) >= MAXPATHLEN ) { ! fprintf( stderr, "%s%s: path too long\n", path, cur->fl_name ); exit( 2 ); } } else { ! if ( snprintf( temp, MAXPATHLEN, "%s/%s", path, cur->fl_name ) >= MAXPATHLEN ) { ! fprintf( stderr, "%s/%s: path too long\n", path, cur->fl_name ); exit( 2 ); } } ! fs_walk( temp, &cur->fl_stat, &cur->fl_type, &cur->fl_afinfo, ! (int)f, (int)( f + chunk )); f += chunk; ! next = cur->fl_next; ! free( cur->fl_name ); ! free( cur ); ! } return; *************** *** 163,166 **** --- 245,250 ---- int finish = 0; struct stat st; + char type; + struct applefileinfo afinfo; edit_path = CREATABLE; *************** *** 258,271 **** } ! /* verify the path we've been given exists */ ! if ( stat( path_prefix, &st ) != 0 ) { perror( path_prefix ); exit( 2 ); } /* initialize the transcripts */ transcript_init( kfile, K_CLIENT ); ! fs_walk( path_prefix, 0, finish ); if ( finish > 0 ) { --- 342,359 ---- } ! if ( radstat( path_prefix, &st, &type, &afinfo ) != 0 ) { perror( path_prefix ); exit( 2 ); } + if (( dotfd = open( ".", O_RDONLY, 0 )) < 0 ) { + perror( "OOPS!" ); + exit( 2 ); + } + /* initialize the transcripts */ transcript_init( kfile, K_CLIENT ); ! fs_walk( path_prefix, &st, &type, &afinfo, 0, finish ); if ( finish > 0 ) { Index: stor.c =================================================================== RCS file: /cvsroot/radmind/radmind/stor.c,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** stor.c 24 Jan 2006 20:44:14 -0000 1.45 --- stor.c 17 Feb 2006 20:30:01 -0000 1.46 *************** *** 258,262 **** int rc = 0, dfd = 0, rfd = 0; off_t size; ! char buf[ 8192 ]; struct timeval tv; unsigned int md_len; --- 258,262 ---- int rc = 0, dfd = 0, rfd = 0; off_t size; ! char buf[ 8192 ], rsrc_path[ MAXPATHLEN ]; struct timeval tv; unsigned int md_len; *************** *** 294,299 **** } if ( afinfo->as_ents[ AS_RFE ].ae_length > 0 ) { ! if (( rfd = open( afinfo->rsrc_path, O_RDONLY )) < 0 ) { ! perror( afinfo->rsrc_path ); close( dfd ); exit( 2 ); --- 294,304 ---- } if ( afinfo->as_ents[ AS_RFE ].ae_length > 0 ) { ! if ( snprintf( rsrc_path, MAXPATHLEN, "%s%s", ! path, _PATH_RSRCFORKSPEC ) >= MAXPATHLEN ) { ! errno = ENAMETOOLONG; ! return( -1 ); ! } ! if (( rfd = open( rsrc_path, O_RDONLY )) < 0 ) { ! perror( rsrc_path ); close( dfd ); exit( 2 ); *************** *** 445,449 **** if ( afinfo->as_ents[ AS_RFE ].ae_length > 0 ) { if ( close( rfd ) < 0 ) { ! perror( afinfo->rsrc_path ); exit( 2 ); } --- 450,454 ---- if ( afinfo->as_ents[ AS_RFE ].ae_length > 0 ) { if ( close( rfd ) < 0 ) { ! perror( rsrc_path ); exit( 2 ); } |