From nobody Sat Jan 01 20:52:53 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 07084191E4B8; Sat, 1 Jan 2022 20:52:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JRDjd4kpVz4q21; Sat, 1 Jan 2022 20:52:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 824FA25819; Sat, 1 Jan 2022 20:52:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 201KqrMq082130; Sat, 1 Jan 2022 20:52:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 201KqrhV082129; Sat, 1 Jan 2022 20:52:53 GMT (envelope-from git) Date: Sat, 1 Jan 2022 20:52:53 GMT Message-Id: <202201012052.201KqrhV082129@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 18f20d5d967a - main - bsddialog: convert bsdinstall/distextract List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 18f20d5d967ae790f121963e1fcee68d729a529e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641070373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4bGgzpW1SPrNSNPGph75DLyQwZDwrgXrYTe6riTDAbA=; b=BfnRxVtzG3BHWjfSmYzFx5v6PL6cAAk2G5NHO+F9QT6WsCJiaM0I0oFZKz5f5V4S/4xmz2 CFratAey+NLIgHgdPE9m0jpk9QFRAu10sOuaizdZ72A9v8y1NZHz1thRmSfHh2N0v02qz+ gpUF2Dfugikra6niEXZhEjc0TZqWg5/pC7hnSv3igBfki9clKlJd0+iExjcKvyb51fHxoc PcQDywEqjZF6oLGX8MUPgA/h+s5C732/fJM+OKohK3mJ/B9NNyv1hlQ2V0OSXWgCOuPbu3 fKGh8bfAP+Gpkbp+3CgSFGHfgKJGgK/zePhMQdpDHVng0lffTD6Tmo/t0rQiSA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641070373; a=rsa-sha256; cv=none; b=gJMLPyNwim7nA+r0Nj3cPyzpRCmXFj45lNFwnqRmdQ8e35dPYBj8z4/QbRlHSnh/TzOfXn 8lPG/eODFuXsr7U5taZtrl3TreivuxZn5HTDBrsBfH6zLkwImvTrr8TPrl031R+O+1JCec FGf0AqQR/nzkHQGP2gi/c5/c5DwbYXLazuEB5mSA94SMEjM0GKY3pMkj1wHYXN92XCF06p KmZ59qLtXeksBl45MRuM+pA1LJBFV+qkqYybfHZaHO4XOfBQXzo6xtNBEJXRzSXUcLGRC4 M8nLPk1TZEMWKt5+GtPWUL/SJTQnsuszIzWddOKIzq5zS8bgv6SALMk3S7WAjg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=18f20d5d967ae790f121963e1fcee68d729a529e commit 18f20d5d967ae790f121963e1fcee68d729a529e Author: Alfonso Siciliano AuthorDate: 2022-01-01 20:50:44 +0000 Commit: Baptiste Daroussin CommitDate: 2022-01-01 20:51:23 +0000 bsddialog: convert bsdinstall/distextract Differential Revision: https://reviews.freebsd.org/D33581 --- usr.sbin/bsdinstall/distextract/Makefile | 3 +- usr.sbin/bsdinstall/distextract/distextract.c | 180 +++++++++++++------------- 2 files changed, 92 insertions(+), 91 deletions(-) diff --git a/usr.sbin/bsdinstall/distextract/Makefile b/usr.sbin/bsdinstall/distextract/Makefile index 2b7180e28ea0..5e9f2b9e1473 100644 --- a/usr.sbin/bsdinstall/distextract/Makefile +++ b/usr.sbin/bsdinstall/distextract/Makefile @@ -2,7 +2,8 @@ BINDIR= ${LIBEXECDIR}/bsdinstall PROG= distextract -LIBADD= archive dpv dialog m +CFLAGS+= -I${SRCTOP}/contrib/bsddialog/lib +LIBADD= archive bsddialog m MAN= diff --git a/usr.sbin/bsdinstall/distextract/distextract.c b/usr.sbin/bsdinstall/distextract/distextract.c index 8ad6c7b2c64b..df10c299ab7f 100644 --- a/usr.sbin/bsdinstall/distextract/distextract.c +++ b/usr.sbin/bsdinstall/distextract/distextract.c @@ -33,11 +33,12 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include +#include +#include #include #include #include +#include #include #include #include @@ -46,30 +47,27 @@ __FBSDID("$FreeBSD$"); /* Data to process */ static char *distdir = 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(struct dpv_file_node *file, int out); +static int extract_files(struct bsddialog_fileminibar *file); -#define _errx(...) (end_dialog(), errx(__VA_ARGS__)) +#define _errx(...) (bsddialog_end(), errx(__VA_ARGS__)) int main(void) { char *chrootdir; char *distributions; + unsigned int i; int retval; - size_t config_size = sizeof(struct dpv_config); - size_t file_node_size = sizeof(struct dpv_file_node); + size_t minibar_size = sizeof(struct bsddialog_fileminibar); size_t span; - 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"; + unsigned int nminibars; + struct bsddialog_fileminibar *dists; + struct bsddialog_progviewconf pvconf; + struct bsddialog_conf conf; struct sigaction act; char error[PATH_MAX + 512]; @@ -78,17 +76,17 @@ main(void) if ((distdir = getenv("BSDINSTALL_DISTDIR")) == NULL) distdir = __DECONST(char *, ""); - /* Initialize dialog(3) */ - init_dialog(stdin, stdout); - dialog_vars.backtitle = backtitle; - dlg_put_backtitle(); - - dialog_msgbox("", - "Checking distribution archives.\nPlease wait...", 4, 35, FALSE); - - /* - * Parse $DISTRIBUTIONS into dpv(3) linked-list - */ + if (bsddialog_init() == BSDDIALOG_ERROR) + errx(EXIT_FAILURE, "Cannot init libbsdialog"); + bsddialog_initconf(&conf); + bsddialog_backtitle(&conf, __DECONST(char *, "FreeBSD Installer")); + bsddialog_infobox(&conf, + __DECONST(char *, "Checking distribution archives.\n" + "Please wait..."), 4, 35); + + /* Parse $DISTRIBUTIONS */ + nminibars = 0; + dists = NULL; while (*distributions != '\0') { span = strcspn(distributions, "\t\n\v\f\r "); if (span < 1) { /* currently on whitespace */ @@ -97,36 +95,36 @@ main(void) } /* Allocate a new struct for the distribution */ - if (dist == NULL) { - if ((dist = calloc(1, file_node_size)) == NULL) - _errx(EXIT_FAILURE, "Out of memory!"); - dists = dist; - } else { - dist->next = calloc(1, file_node_size); - if (dist->next == NULL) - _errx(EXIT_FAILURE, "Out of memory!"); - dist = dist->next; - } + dists = realloc(dists, (nminibars + 1) * minibar_size); + if (dists == NULL) + _errx(EXIT_FAILURE, "Out of memory!"); - /* Set path */ - if ((dist->path = malloc(span + 1)) == NULL) + /* Set file path */ + if ((dists[nminibars].path = malloc(span + 1)) == NULL) _errx(EXIT_FAILURE, "Out of memory!"); - snprintf(dist->path, span + 1, "%s", distributions); - dist->path[span] = '\0'; + snprintf(dists[nminibars].path, span + 1, "%s", distributions); + dists[nminibars].path[span] = '\0'; - /* Set display name */ - dist->name = strrchr(dist->path, '/'); - if (dist->name == NULL) - dist->name = dist->path; + /* Set mini bar label */ + dists[nminibars].label = strrchr(dists[nminibars].path, '/'); + if (dists[nminibars].label == NULL) + dists[nminibars].label = dists[nminibars].path; /* Set initial length in files (-1 == error) */ - dist->length = count_files(dist->path); - if (dist->length < 0) { - end_dialog(); + dists[nminibars].size = count_files(dists[nminibars].path); + if (dists[nminibars].size < 0) { + bsddialog_end(); return (EXIT_FAILURE); } + /* Set initial status to pending */ + /* dists[nminibars].status = 10; */ + + /* Set initial read */ + dists[nminibars].read = 0; + distributions += span; + nminibars += 1; } /* Optionally chdir(2) into $BSDINSTALL_CHROOT */ @@ -135,8 +133,9 @@ main(void) snprintf(error, sizeof(error), "Could not change to directory %s: %s\n", chrootdir, strerror(errno)); - dialog_msgbox("Error", error, 0, 0, TRUE); - end_dialog(); + conf.title = __DECONST(char *, "Error"); + bsddialog_msgbox(&conf, error, 0, 0); + bsddialog_end(); return (EXIT_FAILURE); } @@ -144,32 +143,23 @@ main(void) 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) - free(dist->path); - free(dist); + conf.title = __DECONST(char *, "Archive Extraction"); + pvconf.callback = extract_files; + pvconf.refresh = 1; + pvconf.fmtbottomstr = __DECONST(char *, "%10lli files read @ %'9.1f files/sec."); + bsddialog_total_progview = 0; + bsddialog_interruptprogview = bsddialog_abortprogview = false; + retval = bsddialog_progressview(&conf, + __DECONST(char *, "Extracting distribution files..."), 0, 0, &pvconf, nminibars, dists); + + bsddialog_end(); + + for (i=0; iname, + "Error opening %s: %s\n", file->label, archive_error_string(archive)); - dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); - file->status = DPV_STATUS_FAILED; - dpv_abort = 1; + conf.title = __DECONST(char *, "Extract Error"); + bsddialog_msgbox(&conf, errormsg, 0, 0); + file->status = 1; /* Failed */ + bsddialog_abortprogview = true; return (-1); } } @@ -303,7 +302,7 @@ extract_files(struct dpv_file_node *file, int out __unused) if (retval == ARCHIVE_EOF) { archive_read_free(archive); archive = NULL; - file->status = DPV_STATUS_DONE; + file->status = 5; /*Done*/; return (100); } else if (retval != ARCHIVE_OK && !(retval == ARCHIVE_WARN && @@ -315,20 +314,21 @@ extract_files(struct dpv_file_node *file, int out __unused) * option. */ snprintf(errormsg, sizeof(errormsg), - "Error while extracting %s: %s\n", file->name, + "Error while extracting %s: %s\n", file->label, archive_error_string(archive)); - dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); - file->status = DPV_STATUS_FAILED; - dpv_abort = 1; + conf.title = __DECONST(char *, "Extract Error"); + bsddialog_msgbox(&conf, errormsg, 0, 0); + file->status = 1; /* Failed */ + bsddialog_abortprogview = true; return (-1); } - dpv_overall_read++; + bsddialog_total_progview++; file->read++; /* Calculate [overall] percentage of completion (if possible) */ - if (file->length >= 0) - return (file->read * 100 / file->length); + if (file->size >= 0) + return (file->read * 100 / file->size); else return (-1); }