Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add progress indicators to repo create.
Vsevolod Stakhov committed 11 years ago
commit c2a6a3c822a5fda682e6bd8ff61e69e69acbd1f0
parent f74fd4a
3 files changed +22 -42
modified libpkg/pkg.h.in
@@ -958,12 +958,8 @@ int pkg_is_installed(struct pkgdb *db, const char *origin);
 * @param output_dir The path where the package repository should be created.
 * @param force If true, rebuild the repository catalogue from scratch
 * @param filesite If true, create a list of all files in repo
-
 * @param callback A function which is called at every step of the process.
-
 * @param data A pointer which is passed to the callback.
-
 * @param sum An 65 long char array to receive the sha256 sum
 */
-
int pkg_create_repo(char *path, const char *output_dir, bool filelist,
-
    void (*callback)(struct pkg *, void *), void *);
+
int pkg_create_repo(char *path, const char *output_dir, bool filelist);
int pkg_finish_repo(const char *output_dir, pem_password_cb *cb, char **argv,
    int argc, bool filelist);

modified libpkg/pkg_repo_create.c
@@ -472,8 +472,7 @@ pkg_create_repo_read_pipe(int fd, struct digest_list_entry **dlist)
}

int
-
pkg_create_repo(char *path, const char *output_dir, bool filelist,
-
		void (progress)(struct pkg *pkg, void *data), void *data)
+
pkg_create_repo(char *path, const char *output_dir, bool filelist)
{
	FTS *fts = NULL;
	struct pkg_fts_item *fts_items = NULL, *fts_cur;
@@ -567,6 +566,8 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,
	tasks_per_worker = ceil((double)len / num_workers);

	/* Launch workers */
+
	pkg_emit_progress_start("Creating repository in %s", output_dir);
+

	pfd = calloc(num_workers, sizeof(struct pollfd));
	ntask = 0;
	LL_FOREACH(fts_items, fts_cur) {
@@ -595,6 +596,7 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,
		ntask ++;
	}

+
	ntask = 0;
	while(num_workers > 0) {
		retcode = poll(pfd, num_workers, -1);
		if (retcode == -1) {
@@ -620,11 +622,15 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,

						num_workers --;
					}
+
					else {
+
						pkg_emit_progress_tick(ntask++, len);
+
					}
				}
			}
		}
	}

+
	pkg_emit_progress_tick(len, len);
	retcode = EPKG_OK;

	/* Now sort all digests */
@@ -819,6 +825,7 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
	struct rsa_key *rsa = NULL;
	struct stat st;
	int ret = EPKG_OK;
+
	const int files_to_pack = 3;

	if (!is_dir(output_dir)) {
		pkg_emit_error("%s is not a directory", output_dir);
@@ -837,6 +844,9 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
		argv++;
	}

+
	pkg_emit_progress_start("Packing files for repository", output_dir);
+
	pkg_emit_progress_tick(0, files_to_pack);
+

	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
	    repo_packagesite_file);
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", output_dir,
@@ -846,6 +856,8 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
		goto cleanup;
	}

+
	pkg_emit_progress_tick(1, files_to_pack);
+

	if (filelist) {
		snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
		    repo_filesite_file);
@@ -857,6 +869,8 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
		}
	}

+
	pkg_emit_progress_tick(2, files_to_pack);
+

	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
	    repo_digests_file);
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", output_dir,
@@ -865,6 +879,7 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
		ret = EPKG_FATAL;
		goto cleanup;
	}
+

#if 0
	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
		repo_conflicts_file);
@@ -904,6 +919,8 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
	}

cleanup:
+
	pkg_emit_progress_tick(files_to_pack, files_to_pack);
+

	if (rsa)
		rsa_free(rsa);

modified src/repo.c
@@ -43,24 +43,6 @@ usage_repo(void)
	fprintf(stderr, "For more information see 'pkg help repo'.\n");
}

-
static const char ps[] = { '-', '\\', '|', '/' };
-

-
static void
-
progress(struct pkg *pkg, void *data)
-
{
-
	int *pos;
-

-
	pos = (int *)data;
-

-
	if (*pos == 3)
-
		*pos = 0;
-
	else
-
		*pos = *pos + 1;
-

-
	if (pkg != NULL)
-
		printf("\b%c", ps[*pos]);
-
}
-

static int
password_cb(char *buf, int size, int rwflag, void *key)
{
@@ -137,28 +119,13 @@ exec_repo(int argc, char **argv)
	if (output_dir == NULL)
		output_dir = argv[0];

-
	if (!quiet) {
-
		printf("Generating repository catalog in %s:  ", argv[0]);
-
		if (isatty(STDOUT_FILENO)) {
-
			progress_fn = progress;
-
			pos_ptr = &pos;
-
		}
-
	}
-

-
	ret = pkg_create_repo(argv[0], output_dir, filelist, progress_fn,
-
	    pos_ptr);
+
	ret = pkg_create_repo(argv[0], output_dir, filelist);

	if (ret != EPKG_OK) {
		printf("Cannot create repository catalogue\n");
		return (EX_IOERR);
-
	} else {
-
		if (!quiet) {
-
			if (progress_fn != NULL)
-
				printf("\b");
-
			printf("done!\n");
-
		}
	}
-
	
+

	if (pkg_finish_repo(output_dir, password_cb, argv + 1, argc - 1,
	    filelist) != EPKG_OK)
		return (EX_DATAERR);