Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add WARN_SIZE_LIMIT option
Vsevolod Stakhov committed 10 years ago
commit 9c3d051cdc2fb3c8164846f8e8d1b23fd8ffaa01
parent ef15e05
9 files changed +103 -50
modified libpkg/pkg_config.c
@@ -2,9 +2,9 @@
 * Copyright (c) 2011-2015 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2014 Matthew Seaman <matthew@FreeBSD.org>
-
 * Copyright (c) 2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
+
 * Copyright (c) 2016 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -14,7 +14,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -396,6 +396,12 @@ static struct config_entry c[] = {
		"NO",
		"Enable base libraries analysis",
	},
+
	{
+
		PKG_INT,
+
		"WARN_SIZE_LIMIT",
+
		"1048576", /* 1 meg */
+
		"Ask user when performing changes for more than this limit"
+
	},
};

static bool parsed = false;
modified src/autoremove.c
@@ -2,8 +2,9 @@
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
 * Copyright (c) 2013-2014 Matthew Seaman <matthew@FreeBSD.org>
+
 * Copyright (c) 2016 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -13,7 +14,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -87,7 +88,7 @@ exec_autoremove(int argc, char **argv)
		return (EX_USAGE);
	}

-
	if (dry_run) 
+
	if (dry_run)
		retcode = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL);
	else
		retcode = pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE,
@@ -132,7 +133,7 @@ exec_autoremove(int argc, char **argv)
	}

	if (!quiet || dry_run) {
-
		print_jobs_summary(jobs,
+
		print_jobs_summary(jobs, NULL, NULL,
				"Deinstallation has been requested for the following %d packages:\n\n", nbactions);
		if (!dry_run)
			rc = query_yesno(false,
modified src/check.c
@@ -2,8 +2,9 @@
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
 * Copyright (c) 2014 Matthew Seaman <matthew@FreeBSD.org>
+
 * Copyright (c) 2016 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -13,7 +14,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -198,8 +199,9 @@ fix_deps(struct pkgdb *db, struct deps_entry *dh, int nbpkgs)
	}

	/* print a summary before applying the jobs */
-
	print_jobs_summary(jobs, "The following packages will be installed:\n\n");
-
	
+
	print_jobs_summary(jobs, NULL, NULL,
+
			"The following packages will be installed:\n\n");
+

	rc = query_yesno(false, "\n>>> Try to fix the missing dependencies? ");

	if (rc) {
@@ -233,11 +235,11 @@ check_summary(struct pkgdb *db, struct deps_entry *dh)
	assert(db != NULL);

	printf(">>> Summary of actions performed:\n\n");
-
		
+

	DL_FOREACH(dh, e) {
		if ((it = pkgdb_query(db, e->name, MATCH_EXACT)) == NULL)
			return;
-
		
+

		if (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) != EPKG_OK) {
			fixed = false;
			printf("%s dependency failed to be fixed\n", e->name);
@@ -246,7 +248,7 @@ check_summary(struct pkgdb *db, struct deps_entry *dh)

		pkgdb_it_free(it);
	}
-
	
+

	if (fixed) {
		printf("\n>>> Missing dependencies were fixed successfully.\n");
	} else {
modified src/delete.c
@@ -3,8 +3,9 @@
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
 * Copyright (c) 2013-2014 Matthew Seaman <matthew@FreeBSD.org>
+
 * Copyright (c) 2016 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -14,7 +15,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -204,7 +205,7 @@ exec_delete(int argc, char **argv)

	if (!quiet || dry_run) {
		if (!quiet) {
-
			print_jobs_summary(jobs,
+
			print_jobs_summary(jobs, NULL, NULL,
				"Deinstallation has been requested for the following %d packages "
				"(of %d packages in the universe):\n\n", nbactions,
				pkg_jobs_total(jobs));
modified src/fetch.c
@@ -2,9 +2,9 @@
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
 * Copyright (c) 2013-2014 Matthew Seaman <matthew@FreeBSD.org>
 * Copyright (c) 2012-2013 Bryan Drewery <bdrewery@FreeBSD.org>
-
 * Copyright (c) 2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
+
 * Copyright (c) 2016 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -14,7 +14,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -65,6 +65,9 @@ exec_fetch(int argc, char **argv)
	unsigned	 mode;
	match_t		 match = MATCH_EXACT;
	pkg_flags	 f = PKG_FLAG_NONE;
+
	size_t dlbytes, diffbytes, limbytes;
+

+
	limbytes = pkg_object_int(pkg_config_get("WARN_SIZE_LIMIT"));

	struct option longopts[] = {
		{ "all",		no_argument,		NULL,	'a' },
@@ -129,7 +132,7 @@ exec_fetch(int argc, char **argv)
	}
	argc -= optind;
	argv += optind;
-
	
+

	if (argc < 1 && match != MATCH_ALL && !upgrades_for_installed) {
		usage_fetch();
		return (EX_USAGE);
@@ -200,11 +203,19 @@ exec_fetch(int argc, char **argv)
		goto cleanup;

	if (!quiet) {
-
		rc = print_jobs_summary(jobs, "The following packages will be fetched:\n\n");

-
		if (rc != 0)
-
			rc = query_yesno(false, "\nProceed with fetching "
-
			    "packages? ");
+
		rc = print_jobs_summary(jobs, &diffbytes, &dlbytes,
+
				"The following packages will be fetched:\n\n");
+

+
		if (rc != 0) {
+
			if (limbytes && (diffbytes > limbytes || dlbytes > limbytes)) {
+
				rc = query_yesno(false, "\nProceed with fetching "
+
						"packages? ");
+
			}
+
			else {
+
				rc = true;
+
			}
+
		}
		else {
			printf("No packages are required to be fetched.\n");
			rc = query_yesno(false, "Check the integrity of packages "
@@ -215,7 +226,7 @@ exec_fetch(int argc, char **argv)
	else {
		rc = true;
	}
-
	
+

	if (!rc || (retcode = pkg_jobs_apply(jobs)) != EPKG_OK)
		goto cleanup;

modified src/install.c
@@ -4,8 +4,9 @@
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
 * Copyright (c) 2013-2014 Matthew Seaman <matthew@FreeBSD.org>
 * Copyright (c) 2012-2013 Bryan Drewery <bdrewery@FreeBSD.org>
+
 * Copyright (c) 2016 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -15,7 +16,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -67,6 +68,9 @@ exec_install(int argc, char **argv)
	bool		 local_only = false;
	match_t		 match = MATCH_EXACT;
	pkg_flags	 f = PKG_FLAG_NONE | PKG_FLAG_PKG_VERSION_TEST;
+
	size_t dlbytes, diffbytes, limbytes;
+

+
	limbytes = pkg_object_int(pkg_config_get("WARN_SIZE_LIMIT"));

	struct option longopts[] = {
		{ "automatic",		no_argument,		NULL,	'A' },
@@ -226,13 +230,18 @@ exec_install(int argc, char **argv)
		rc = yes;
		/* print a summary before applying the jobs */
		if (!quiet || dry_run) {
-
			print_jobs_summary(jobs,
+
			print_jobs_summary(jobs, &diffbytes, &dlbytes,
			    "The following %d package(s) will be affected (of %d checked):\n\n",
			    nbactions, pkg_jobs_total(jobs));

			if (!dry_run) {
-
				rc = query_yesno(false,
-
				    "\nProceed with this action? ");
+
				if (limbytes && (diffbytes > limbytes || dlbytes > limbytes)) {
+
					rc = query_yesno(false,
+
				      "\nProceed with this action? ");
+
				}
+
				else {
+
					rc = true;
+
				}
			}
			else {
				rc = false;
modified src/pkgcli.h
@@ -2,7 +2,7 @@
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2013 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -12,7 +12,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -266,7 +266,10 @@ int query_select(const char *msg, const char **opts, int ncnt, int deft);
bool query_tty_yesno(bool deft, const char *msg, ...);
int info_flags(uint64_t opt, bool remote);
void print_info(struct pkg * const pkg, uint64_t opt);
-
int print_jobs_summary(struct pkg_jobs *j, const char *msg, ...);
+
int print_jobs_summary(struct pkg_jobs *j,
+
		size_t *bytes_change,
+
		size_t *bytes_download,
+
		const char *msg, ...);

void job_status_begin(struct sbuf *);
void job_status_end(struct sbuf *);
modified src/upgrade.c
@@ -2,8 +2,9 @@
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2013 Matthew Seaman <matthew@FreeBSD.org>
 * Copyright (c) 2012-2013 Bryan Drewery <bdrewery@FreeBSD.org>
+
 * Copyright (c) 2016 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -13,7 +14,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -57,6 +58,9 @@ exec_upgrade(int argc, char **argv)
	int		 done = 0;
	bool	rc = true;
	pkg_flags	 f = PKG_FLAG_NONE | PKG_FLAG_PKG_VERSION_TEST;
+
	size_t dlbytes, diffbytes, limbytes;
+

+
	limbytes = pkg_object_int(pkg_config_get("WARN_SIZE_LIMIT"));

	struct option longopts[] = {
		{ "case-sensitive",	no_argument,		NULL,	'C' },
@@ -147,7 +151,7 @@ exec_upgrade(int argc, char **argv)
		return (EX_IOERR);
	else
		retcode = EX_SOFTWARE;
-
	
+

	/* first update the remote repositories if needed */
	if (auto_update &&
	    (updcode = pkgcli_update(false, false, reponame)) != EPKG_OK)
@@ -181,15 +185,22 @@ exec_upgrade(int argc, char **argv)
		/* print a summary before applying the jobs */
		rc = yes;
		if (!quiet || dry_run) {
-
			print_jobs_summary(jobs,
+
			print_jobs_summary(jobs, &diffbytes, &dlbytes,
				"The following %d package(s) will be affected (of %d checked):\n\n",
				nbactions, pkg_jobs_total(jobs));

-
			if (!dry_run)
-
				rc = query_yesno(false, "\nProceed with this "
-
				    "action? ");
-
			else
+
			if (!dry_run) {
+
				if (limbytes && (diffbytes > limbytes || dlbytes > limbytes)) {
+
					rc = query_yesno(false, "\nProceed with this "
+
							"action? ");
+
				}
+
				else {
+
					rc = true;
+
				}
+
			}
+
			else {
				rc = false;
+
			}
		}

		if (rc) {
modified src/utils.c
@@ -3,9 +3,9 @@
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
 * Copyright (c) 2012-2015 Matthew Seaman <matthew@FreeBSD.org>
-
 * Copyright (c) 2013-2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
+
 * Copyright (c) 2013-2016 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -15,7 +15,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -369,7 +369,7 @@ print_info(struct pkg * const pkg, uint64_t options)
	   style to show on a new line.  */

	info_num = 0;
-
	for (opt = 0x1U; opt <= INFO_LASTFIELD; opt <<= 1) 
+
	for (opt = 0x1U; opt <= INFO_LASTFIELD; opt <<= 1)
		if ((opt & options) != 0)
			info_num++;

@@ -457,7 +457,7 @@ print_info(struct pkg * const pkg, uint64_t options)
				printf("%-15s: ", "Maintainer");
			pkg_printf("%m\n", pkg);
			break;
-
		case INFO_WWW:	
+
		case INFO_WWW:
			if (print_tag)
				printf("%-15s: ", "WWW");
			pkg_printf("%w\n", pkg);
@@ -471,7 +471,7 @@ print_info(struct pkg * const pkg, uint64_t options)
			if (pkg_list_count(pkg, PKG_OPTIONS) > 0) {
				if (print_tag)
					printf("%-15s:\n", "Options");
-
				if (quiet) 
+
				if (quiet)
					pkg_printf("%O%{%-15On: %Ov\n%|%}", pkg);
				else
					pkg_printf("%O%{\t%-15On: %Ov\n%|%}", pkg);
@@ -571,7 +571,7 @@ print_info(struct pkg * const pkg, uint64_t options)
				if (print_tag)
					printf("%-15s:\n", "Required by");
				if (quiet) {
-
					if (show_locks) 
+
					if (show_locks)
						pkg_printf("%r%{%rn-%rv%#rk\n%|%}", pkg);
					else
						pkg_printf("%r%{%rn-%rv\n%|%}", pkg);
@@ -875,7 +875,8 @@ static const char* pkg_display_messages[PKG_DISPLAY_MAX + 1] = {
};

int
-
print_jobs_summary(struct pkg_jobs *jobs, const char *msg, ...)
+
print_jobs_summary(struct pkg_jobs *jobs, size_t *bytes_change, size_t *bytes_download,
+
		const char *msg, ...)
{
	struct pkg *new_pkg, *old_pkg;
	void *iter = NULL;
@@ -937,6 +938,14 @@ print_jobs_summary(struct pkg_jobs *jobs, const char *msg, ...)
		printf("%s to be downloaded.\n", size);
	}

+
	if (bytes_download) {
+
		*bytes_download = dlsize;
+
	}
+

+
	if (bytes_change) {
+
		*bytes_change = labs(newsize - oldsize);
+
	}
+

	return (displayed);
}