From owner-p4-projects@FreeBSD.ORG Tue Jul 5 10:32:06 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 080A916A420; Tue, 5 Jul 2005 10:32:06 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D5DDA16A41C for ; Tue, 5 Jul 2005 10:32:05 +0000 (GMT) (envelope-from soc-andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id A28F043D55 for ; Tue, 5 Jul 2005 10:32:05 +0000 (GMT) (envelope-from soc-andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j65AW5Je072363 for ; Tue, 5 Jul 2005 10:32:05 GMT (envelope-from soc-andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j65AW5Z0072360 for perforce@freebsd.org; Tue, 5 Jul 2005 10:32:05 GMT (envelope-from soc-andrew@freebsd.org) Date: Tue, 5 Jul 2005 10:32:05 GMT Message-Id: <200507051032.j65AW5Z0072360@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-andrew@freebsd.org using -f From: soc-andrew To: Perforce Change Reviews Cc: Subject: PERFORCE change 79593 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2005 10:32:06 -0000 http://perforce.freebsd.org/chv.cgi?CH=79593 Change 79593 by soc-andrew@soc-andrew_serv on 2005/07/05 10:31:48 Implement a callback for when the next file is opened for reading by libarchive. Affected files ... .. //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/dist.c#3 edit .. //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/extract.c#2 edit .. //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/extract.h#2 edit Differences ... ==== //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/dist.c#3 (text+ko) ==== @@ -41,6 +41,8 @@ static char base[PATH_MAX]; static char location[PATH_MAX]; +static void dist_change_file_callback(int, char *); + /* * Process a .inf file * dir is the directory relative to base, eg src @@ -139,6 +141,15 @@ free(f); } +static void +dist_change_file_callback(int pcnt, char *name) { + printf("%d%%", pcnt); + if (name) + printf(" %s", name); + + putchar('\n'); +} + void dist_extract(const char *dist) { struct inf_file * inf; @@ -166,7 +177,7 @@ archive_read_support_compression_all(a); archive_read_support_format_all(a); if(read_open_split(a, basename, (inf->pieces / 26) + 'a', - (inf->pieces % 26) + 'a') != ARCHIVE_OK) { + (inf->pieces % 26) + 'a', dist_change_file_callback) != ARCHIVE_OK) { printf("ERROR: %s\n", archive_error_string(a)); archive_read_finish(a); inf_free(inf); ==== //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/extract.c#2 (text+ko) ==== @@ -24,8 +24,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include + #include #include +#include #include #include #include @@ -35,11 +38,12 @@ #define block_size 10240 struct file_list { - char *basename; /* The name of the file without the last 2 characters */ + char *basename; /* Name of the file without the last 2 characters */ char end[2]; /* The characters to end on */ char current[2]; /* The current characters to use */ FILE *fd; void *buff; + void (*new_file)(int, char*); }; static int open_current(struct archive *a, struct file_list *fl); @@ -53,28 +57,29 @@ */ static int open_current(struct archive *a, struct file_list *fl) { - char *file = malloc(strlen(fl->basename) + 4); - if (file == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return ARCHIVE_FATAL; - } + char file[PATH_MAX]; if (fl->fd != NULL) fclose(fl->fd); - sprintf(file, "%s%c%c", fl->basename, fl->current[0], fl->current[1]); + snprintf(file, PATH_MAX, "%s%c%c", fl->basename, fl->current[0], fl->current[1]); fl->fd = fopen(file, "r"); + if(fl->new_file != NULL) { + int file_no = (fl->current[0] - 'a') * 26 + (fl->current[1] - 'a'); + int total = (fl->end[0] - 'a') * 26 + (fl->end[1] - 'a'); + snprintf(file, PATH_MAX, "%s%c%c", basename(fl->basename), + fl->current[0], fl->current[1]); + (*fl->new_file)((int)(((double)file_no/total)*100), file); + } + if (fl->fd == NULL) { /* XXX use archive_set_error() */ archive_set_error(a, ENOENT, "File not found %s", file); - free(file); return ARCHIVE_FATAL; } - free(file); - return ARCHIVE_OK; } @@ -132,9 +137,13 @@ static int close_callback(struct archive *a __unused, void *client_data) { - fclose(((struct file_list*)client_data)->fd); + struct file_list *fl = client_data; + + if(fl->new_file != NULL) { + (*fl->new_file)(100, NULL); + } - struct file_list *fl = client_data; + fclose(fl->fd); free(fl->buff); free(fl->basename); @@ -148,7 +157,7 @@ * extract them in a similar way to archive_read_open_fd */ int -read_open_split(struct archive *a, const char *base_name, char end_0, char end_1) { +read_open_split(struct archive *a, const char *base_name, char end_0, char end_1, void (*nf)(int, char*)) { struct file_list *fl; fl = malloc(sizeof(struct file_list)); @@ -157,6 +166,8 @@ return ARCHIVE_FATAL; } + fl->new_file = nf; + fl->current[0] = 'a'; fl->current[1] = 'a'; @@ -171,3 +182,4 @@ return ARCHIVE_OK; } + ==== //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/extract.h#2 (text+ko) ==== @@ -27,6 +27,6 @@ #ifndef _EXTRACT_H_ #define _EXTRACT_H_ -int read_open_split(struct archive *a, const char *base_name, char end_0, char end_1); +int read_open_split(struct archive *a, const char *base_name, char end_0, char end_1, void (*nf)(int, char*)); #endif /* _EXTRACT_H_ */