コード例 #1
0
ファイル: fetch_cb.c プロジェクト: bougyman/xbps
/*
 * Compute and display transfer rate
 */
static const char *
stat_bps(const struct xbps_fetch_cb_data *xfpd, void *cbdata)
{
	struct xferstat *xfer = cbdata;
	static char str[16];
	char size[8];
	double delta, bps;

	delta = (xfer->last.tv_sec + (xfer->last.tv_usec / 1.e6))
	    - (xfer->start.tv_sec + (xfer->start.tv_usec / 1.e6));
	if (compare_double(delta, 0.0001)) {
		snprintf(str, sizeof str, "-- stalled --");
	} else {
		bps = ((double)(xfpd->file_dloaded-xfpd->file_offset)/delta);
		(void)xbps_humanize_number(size, (int64_t)bps);
		snprintf(str, sizeof str, "%s/s", size);
	}
	return str;
}
コード例 #2
0
ファイル: transaction.c プロジェクト: uggedal/xbps
static int
show_transaction_sizes(struct transaction *trans, int cols)
{
	uint64_t dlsize = 0, instsize = 0, rmsize = 0, disk_free_size = 0;
	char size[8];

	if (!print_trans_colmode(trans, cols)) {
		/*
		 * Show the list of packages that will be downloaded, installed, updated,
		 * removed or configured.
		 */
		xbps_dictionary_get_uint32(trans->d, "total-download-pkgs",
		    &trans->dl_pkgcnt);
		if (trans->dl_pkgcnt) {
			printf("%u package%s will be downloaded:\n",
			    trans->dl_pkgcnt, trans->dl_pkgcnt == 1 ? "" : "s");
			show_package_list(trans, NULL, cols);
			printf("\n");
		}
		xbps_dictionary_get_uint32(trans->d, "total-install-pkgs",
		    &trans->inst_pkgcnt);
		if (trans->inst_pkgcnt) {
			printf("%u package%s will be installed:\n",
			    trans->inst_pkgcnt, trans->inst_pkgcnt == 1 ? "" : "s");
			show_package_list(trans, "install", cols);
			printf("\n");
		}
		xbps_dictionary_get_uint32(trans->d, "total-update-pkgs",
		    &trans->up_pkgcnt);
		if (trans->up_pkgcnt) {
			printf("%u package%s will be updated:\n",
			    trans->up_pkgcnt, trans->up_pkgcnt == 1 ? "" : "s");
			show_package_list(trans, "update", cols);
			printf("\n");
		}
		xbps_dictionary_get_uint32(trans->d, "total-configure-pkgs",
		    &trans->cf_pkgcnt);
		if (trans->cf_pkgcnt) {
			printf("%u package%s will be configured:\n",
			    trans->cf_pkgcnt, trans->cf_pkgcnt == 1 ? "" : "s");
			show_package_list(trans, "configure", cols);
			printf("\n");
		}
		xbps_dictionary_get_uint32(trans->d, "total-remove-pkgs",
		    &trans->rm_pkgcnt);
		if (trans->rm_pkgcnt) {
			printf("%u package%s will be removed:\n",
			    trans->rm_pkgcnt, trans->rm_pkgcnt == 1 ? "" : "s");
			show_package_list(trans, "remove", cols);
			printf("\n");
		}
	}
	/*
	 * Show total download/installed/removed size for all required packages.
	 */
	xbps_dictionary_get_uint64(trans->d, "total-download-size", &dlsize);
	xbps_dictionary_get_uint64(trans->d, "total-installed-size", &instsize);
	xbps_dictionary_get_uint64(trans->d, "total-removed-size", &rmsize);
	xbps_dictionary_get_uint64(trans->d, "disk-free-size", &disk_free_size);
	if (dlsize || instsize || rmsize || disk_free_size)
		printf("\n");

	if (dlsize) {
		if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
			xbps_error_printf("humanize_number returns "
			    "%s\n", strerror(errno));
			return -1;
		}
		printf("Size to download:             %6s\n", size);
	}
	if (instsize) {
		if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
			xbps_error_printf("humanize_number2 returns "
			    "%s\n", strerror(errno));
			return -1;
		}
		printf("Size required on disk:        %6s\n", size);
	}
	if (rmsize) {
		if (xbps_humanize_number(size, (int64_t)rmsize) == -1) {
			xbps_error_printf("humanize_number3 returns "
			    "%s\n", strerror(errno));
			return -1;
		}
		printf("Size freed on disk:           %6s\n", size);
	}
	if (disk_free_size) {
		if (xbps_humanize_number(size, (int64_t)disk_free_size) == -1) {
			xbps_error_printf("humanize_number3 returns "
			    "%s\n", strerror(errno));
			return -1;
		}
		printf("Free space on disk:           %6s\n", size);
	}
	printf("\n");

	return 0;
}
コード例 #3
0
ファイル: transaction.c プロジェクト: uggedal/xbps
int
exec_transaction(struct xbps_handle *xhp, int maxcols, bool yes, bool drun)
{
	xbps_array_t array;
	struct transaction *trans;
	uint64_t fsize = 0, isize = 0;
	char freesize[8], instsize[8];
	int rv = 0;

	trans = calloc(1, sizeof(*trans));
	if (trans == NULL)
		return ENOMEM;

	if ((rv = xbps_transaction_prepare(xhp)) != 0) {
		if (rv == ENODEV) {
			array = xbps_dictionary_get(xhp->transd, "missing_deps");
			if (xbps_array_count(array)) {
				/* missing dependencies */
				print_array(array);
				fprintf(stderr, "Transaction aborted due to unresolved dependencies.\n");
			}
		} else if (rv == ENOEXEC) {
			array = xbps_dictionary_get(xhp->transd, "missing_shlibs");
			if (xbps_array_count(array)) {
				/* missing shlibs */
				print_array(array);
				fprintf(stderr, "Transaction aborted due to unresolved shlibs.\n");
			}
		} else if (rv == EAGAIN) {
			/* conflicts */
			array = xbps_dictionary_get(xhp->transd, "conflicts");
			print_array(array);
			fprintf(stderr, "Transaction aborted due to conflicting packages.\n");
		} else if (rv == ENOSPC) {
			/* not enough free space */
			xbps_dictionary_get_uint64(xhp->transd,
			    "total-installed-size", &isize);
			if (xbps_humanize_number(instsize, (int64_t)isize) == -1) {
				xbps_error_printf("humanize_number2 returns "
					"%s\n", strerror(errno));
				return -1;
			}
			xbps_dictionary_get_uint64(xhp->transd,
			    "disk-free-size", &fsize);
			if (xbps_humanize_number(freesize, (int64_t)fsize) == -1) {
				xbps_error_printf("humanize_number2 returns "
					"%s\n", strerror(errno));
				return -1;
			}
			fprintf(stderr, "Transaction aborted due to insufficient disk "
			    "space (need %s, got %s free).\n", instsize, freesize);
		} else {
			xbps_dbg_printf(xhp, "Empty transaction dictionary: %s\n",
			    strerror(errno));
		}
		goto out;
	}
#ifdef FULL_DEBUG
	xbps_dbg_printf(xhp, "Dictionary before transaction happens:\n");
	xbps_dbg_printf_append(xhp, "%s",
	    xbps_dictionary_externalize(xhp->transd));
#endif

	trans->xhp = xhp;
	trans->d = xhp->transd;
	trans->iter = xbps_array_iter_from_dict(xhp->transd, "packages");
	assert(trans->iter);

	/*
	 * dry-run mode, show what would be done but don't run anything.
	 */
	if (drun) {
		show_actions(trans->iter);
		goto out;
	}
	/*
	 * Show download/installed size for the transaction.
	 */
	if ((rv = show_transaction_sizes(trans, maxcols)) != 0)
		goto out;
	/*
	 * Ask interactively (if -y not set).
	 */
	if (!yes && !yesno("Do you want to continue?")) {
		printf("Aborting!\n");
		goto out;
	}
	/*
	 * It's time to run the transaction!
	 */
	if ((rv = xbps_transaction_commit(xhp)) == 0) {
		printf("\n%u downloaded, %u installed, %u updated, "
		    "%u configured, %u removed.\n",
		    trans->dl_pkgcnt, trans->inst_pkgcnt,
		    trans->up_pkgcnt, trans->cf_pkgcnt + trans->inst_pkgcnt,
		    trans->rm_pkgcnt);
	}
out:
	if (trans->iter)
		xbps_object_iterator_release(trans->iter);
	if (trans)
		free(trans);
	return rv;
}
コード例 #4
0
ファイル: transaction.c プロジェクト: prodigeni/xbps
static int
show_transaction_sizes(struct transaction *trans, int cols)
{
	uint64_t dlsize = 0, instsize = 0, rmsize = 0;
	char size[8];

	/*
	 * Show the list of packages that will be installed.
	 */
	if (xbps_dictionary_get_uint32(trans->d, "total-install-pkgs",
	    &trans->inst_pkgcnt)) {
		printf("%u package%s will be installed:\n",
		    trans->inst_pkgcnt, trans->inst_pkgcnt == 1 ? "" : "s");
		show_package_list(trans->iter, "install", cols);
		printf("\n");
	}
	if (xbps_dictionary_get_uint32(trans->d, "total-update-pkgs",
	    &trans->up_pkgcnt)) {
		printf("%u package%s will be updated:\n",
		    trans->up_pkgcnt, trans->up_pkgcnt == 1 ? "" : "s");
		show_package_list(trans->iter, "update", cols);
		printf("\n");
	}
	if (xbps_dictionary_get_uint32(trans->d, "total-configure-pkgs",
	    &trans->cf_pkgcnt)) {
		printf("%u package%s will be configured:\n",
		    trans->cf_pkgcnt, trans->cf_pkgcnt == 1 ? "" : "s");
		show_package_list(trans->iter, "configure", cols);
		printf("\n");
	}
	if (xbps_dictionary_get_uint32(trans->d, "total-remove-pkgs",
	    &trans->rm_pkgcnt)) {
		printf("%u package%s will be removed:\n",
		    trans->rm_pkgcnt, trans->rm_pkgcnt == 1 ? "" : "s");
		show_package_list(trans->iter, "remove", cols);
		printf("\n");
	}
	/*
	 * Show total download/installed/removed size for all required packages.
	 */
	xbps_dictionary_get_uint64(trans->d, "total-download-size", &dlsize);
	xbps_dictionary_get_uint64(trans->d, "total-installed-size",
	    &instsize);
	xbps_dictionary_get_uint64(trans->d, "total-removed-size", &rmsize);
	if (dlsize || instsize || rmsize)
		printf("\n");

	if (dlsize) {
		if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
			xbps_error_printf("humanize_number returns "
			    "%s\n", strerror(errno));
			return -1;
		}
		printf("Total download size:\t%6s\n", size);
	}
	if (instsize) {
		if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
			xbps_error_printf("humanize_number2 returns "
			    "%s\n", strerror(errno));
			return -1;
		}
		printf("Total installed size:\t%6s\n", size);
	}
	if (rmsize) {
		if (xbps_humanize_number(size, (int64_t)rmsize) == -1) {
			xbps_error_printf("humanize_number3 returns "
			    "%s\n", strerror(errno));
			return -1;
		}
		printf("Total freed size:\t%6s\n", size);
	}
	printf("\n");

	return 0;
}