From owner-svn-src-all@FreeBSD.ORG Thu Dec 18 03:51:11 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4DA9F451; Thu, 18 Dec 2014 03:51:11 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2E77812FD; Thu, 18 Dec 2014 03:51:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBI3pBOS093977; Thu, 18 Dec 2014 03:51:11 GMT (envelope-from dteske@FreeBSD.org) Received: (from dteske@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBI3pA9h093973; Thu, 18 Dec 2014 03:51:10 GMT (envelope-from dteske@FreeBSD.org) Message-Id: <201412180351.sBI3pA9h093973@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: dteske set sender to dteske@FreeBSD.org using -f From: Devin Teske Date: Thu, 18 Dec 2014 03:51:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r275874 - head/usr.sbin/bsdinstall/distextract X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Dec 2014 03:51:11 -0000 Author: dteske Date: Thu Dec 18 03:51:09 2014 New Revision: 275874 URL: https://svnweb.freebsd.org/changeset/base/275874 Log: In bsdinstall's distextract, replace mixed_gauge() of dialog(3) with new dpv(3) wrapper to dialog(3) dialog_gauge(). The dpv(3) library provides a more flexible and refined interface similar to dialog_mixedgauge() however is implemented atop the more generalized dialog_gauge() for portability. Noticeable improvements in bsdinstall's distextract will be a status line showing data rate information (with support for localeconv(3) to format numbers according to $LANG or $LC_ALL conversion information), i18n support, improved auto-sizing of gauge widget, a ``wheel barrow'' to keep the user informed that things are moving (even if status/progress has not changed), improved color support (mini-progress bars use the same color, if enabled, as the main gauge bar), and several other improvements (some not visible). dpv stands for "dialog progress view" (dpv was introduced in SVN r274116). Differential Revision: https://reviews.freebsd.org/D714 Discussed on: -current Reviewed by: julian MFC after: 3 days X-MFC-to: stable/10 Relnotes: Improved installer feedback from bsdinstall distextract Modified: head/usr.sbin/bsdinstall/distextract/Makefile head/usr.sbin/bsdinstall/distextract/distextract.c Modified: head/usr.sbin/bsdinstall/distextract/Makefile ============================================================================== --- head/usr.sbin/bsdinstall/distextract/Makefile Thu Dec 18 03:12:46 2014 (r275873) +++ head/usr.sbin/bsdinstall/distextract/Makefile Thu Dec 18 03:51:09 2014 (r275874) @@ -2,7 +2,7 @@ BINDIR= /usr/libexec/bsdinstall PROG= distextract -LIBADD= archive ncursesw dialog m +LIBADD= archive dpv figpar ncursesw dialog m WARNS?= 6 MAN= Modified: head/usr.sbin/bsdinstall/distextract/distextract.c ============================================================================== --- head/usr.sbin/bsdinstall/distextract/distextract.c Thu Dec 18 03:12:46 2014 (r275873) +++ head/usr.sbin/bsdinstall/distextract/distextract.c Thu Dec 18 03:51:09 2014 (r275874) @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -42,17 +43,13 @@ __FBSDID("$FreeBSD$"); /* Data to process */ static char *distdir = NULL; -struct file_node { - char *path; - char *name; - int length; - struct file_node *next; -}; -static struct file_node *dists = NULL; +static struct archive *archive = NULL; +static struct dpv_file_node *dists = NULL; /* Function prototypes */ +static void sig_int(int sig); static int count_files(const char *file); -static int extract_files(int nfiles, struct file_node *files); +static int extract_files(struct dpv_file_node *file, int out); #if __FreeBSD_version <= 1000008 /* r232154: bump for libarchive update */ #define archive_read_support_filter_all(x) \ @@ -66,11 +63,17 @@ main(void) { char *chrootdir; char *distributions; - int ndists = 0; int retval; - size_t file_node_size = sizeof(struct file_node); + size_t config_size = sizeof(struct dpv_config); + size_t file_node_size = sizeof(struct dpv_file_node); size_t span; - struct file_node *dist = dists; + struct dpv_config *config; + struct dpv_file_node *dist = dists; + static char backtitle[] = "FreeBSD Installer"; + static char title[] = "Archive Extraction"; + static char aprompt[] = "\n Overall Progress:"; + static char pprompt[] = "Extracting distribution files...\n"; + struct sigaction act; char error[PATH_MAX + 512]; if ((distributions = getenv("DISTRIBUTIONS")) == NULL) @@ -80,14 +83,14 @@ main(void) /* Initialize dialog(3) */ init_dialog(stdin, stdout); - dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer"); + dialog_vars.backtitle = backtitle; dlg_put_backtitle(); dialog_msgbox("", "Checking distribution archives.\nPlease wait...", 4, 35, FALSE); /* - * Parse $DISTRIBUTIONS into linked-list + * Parse $DISTRIBUTIONS into dpv(3) linked-list */ while (*distributions != '\0') { span = strcspn(distributions, "\t\n\v\f\r "); @@ -95,7 +98,6 @@ main(void) distributions++; continue; } - ndists++; /* Allocate a new struct for the distribution */ if (dist == NULL) { @@ -141,10 +143,30 @@ main(void) return (EXIT_FAILURE); } - retval = extract_files(ndists, dists); + /* Set cleanup routine for Ctrl-C action */ + act.sa_handler = sig_int; + sigaction(SIGINT, &act, 0); + /* + * Hand off to dpv(3) + */ + if ((config = calloc(1, config_size)) == NULL) + _errx(EXIT_FAILURE, "Out of memory!"); + config->backtitle = backtitle; + config->title = title; + config->pprompt = pprompt; + config->aprompt = aprompt; + config->options |= DPV_WIDE_MODE; + config->label_size = -1; + config->action = extract_files; + config->status_solo = + "%10lli files read @ %'9.1f files/sec."; + config->status_many = + "%10lli files read @ %'9.1f files/sec. [%i/%i busy/wait]"; end_dialog(); + retval = dpv(config, dists); + dpv_free(); while ((dist = dists) != NULL) { dists = dist->next; if (dist->path != NULL) @@ -155,6 +177,12 @@ main(void) return (retval); } +static void +sig_int(int sig __unused) +{ + dpv_interrupt = TRUE; +} + /* * Returns number of files in archive file. Parses $BSDINSTALL_DISTDIR/MANIFEST * if it exists, otherwise uses archive(3) to read the archive file. @@ -167,7 +195,6 @@ count_files(const char *file) int file_count; int retval; size_t span; - struct archive *archive; struct archive_entry *entry; char line[512]; char path[PATH_MAX]; @@ -220,6 +247,7 @@ count_files(const char *file) "Error while extracting %s: %s\n", file, archive_error_string(archive)); dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); + archive = NULL; return (-1); } @@ -227,49 +255,27 @@ count_files(const char *file) while (archive_read_next_header(archive, &entry) == ARCHIVE_OK) file_count++; archive_read_free(archive); + archive = NULL; return (file_count); } static int -extract_files(int nfiles, struct file_node *files) +extract_files(struct dpv_file_node *file, int out __unused) { - int archive_file; - int archive_files[nfiles]; - int current_files = 0; - int i; - int last_progress; - int progress = 0; int retval; - int total_files = 0; - struct archive *archive; struct archive_entry *entry; - struct file_node *file; - char status[8]; - static char title[] = "Archive Extraction"; - static char pprompt[] = "Extracting distribution files...\n"; char path[PATH_MAX]; char errormsg[PATH_MAX + 512]; - const char *items[nfiles*2]; - - /* Make the transfer list for dialog */ - i = 0; - for (file = files; file != NULL; file = file->next) { - items[i*2] = file->name; - items[i*2 + 1] = "Pending"; - archive_files[i] = file->length; - - total_files += file->length; - i++; - } - i = 0; - for (file = files; file != NULL; file = file->next) { + /* Open the archive if necessary */ + if (archive == NULL) { if ((archive = archive_read_new()) == NULL) { snprintf(errormsg, sizeof(errormsg), "Error: %s\n", archive_error_string(NULL)); dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); - return (EXIT_FAILURE); + dpv_abort = 1; + return (-1); } archive_read_support_format_all(archive); archive_read_support_filter_all(archive); @@ -280,59 +286,44 @@ extract_files(int nfiles, struct file_no "Error opening %s: %s\n", file->name, archive_error_string(archive)); dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); - return (EXIT_FAILURE); - } - - items[i*2 + 1] = "In Progress"; - archive_file = 0; - - dialog_mixedgauge(title, pprompt, 0, 0, progress, nfiles, - __DECONST(char **, items)); - - while ((retval = archive_read_next_header(archive, &entry)) == - ARCHIVE_OK) { - last_progress = progress; - progress = (current_files*100)/total_files; - - snprintf(status, sizeof(status), "-%d", - (archive_file*100)/archive_files[i]); - items[i*2 + 1] = status; - - if (progress > last_progress) - dialog_mixedgauge(title, pprompt, 0, 0, - progress, nfiles, - __DECONST(char **, items)); - - retval = archive_read_extract(archive, entry, - ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_OWNER | - ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL | - ARCHIVE_EXTRACT_XATTR | ARCHIVE_EXTRACT_FFLAGS); - - if (retval != ARCHIVE_OK) - break; - - archive_file++; - current_files++; + file->status = DPV_STATUS_FAILED; + dpv_abort = 1; + return (-1); } + } - items[i*2 + 1] = "Done"; - - if (retval != ARCHIVE_EOF) { - snprintf(errormsg, sizeof(errormsg), - "Error while extracting %s: %s\n", items[i*2], - archive_error_string(archive)); - items[i*2 + 1] = "Failed"; - dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); - return (retval); - } + /* Read the next archive header */ + retval = archive_read_next_header(archive, &entry); - progress = (current_files*100)/total_files; - dialog_mixedgauge(title, pprompt, 0, 0, progress, nfiles, - __DECONST(char **, items)); + /* If that went well, perform the extraction */ + if (retval == ARCHIVE_OK) + retval = archive_read_extract(archive, entry, + ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_OWNER | + ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL | + ARCHIVE_EXTRACT_XATTR | ARCHIVE_EXTRACT_FFLAGS); + /* Test for either EOF or error */ + if (retval == ARCHIVE_EOF) { archive_read_free(archive); - i++; + archive = NULL; + file->status = DPV_STATUS_DONE; + return (100); + } else if (retval != ARCHIVE_OK) { + snprintf(errormsg, sizeof(errormsg), + "Error while extracting %s: %s\n", file->name, + archive_error_string(archive)); + dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); + file->status = DPV_STATUS_FAILED; + dpv_abort = 1; + return (-1); } - return (EXIT_SUCCESS); + dpv_overall_read++; + file->read++; + + /* Calculate [overall] percentage of completion (if possible) */ + if (file->length >= 0) + return (file->read * 100 / file->length); + else + return (-1); }