Beispiel #1
0
static int gzprintf_hooks(struct fzp *fzp, struct hooks *hooks)
{
	size_t i;
	fzp_printf(fzp, "%c%04lX%s\n", CMD_MANIFEST,
		strlen(hooks->path), hooks->path);
	for(i=0; i<hooks->len; i++)
		if(to_fzp_fingerprint(fzp, hooks->fingerprints[i]))
			return -1;
	return 0;
}
Beispiel #2
0
static int sort_and_write_hooks(struct manio *manio)
{
	int i;
	int ret=-1;
	struct fzp *fzp=NULL;
	char msg[32]="";
	char *path=NULL;
	int hook_count=manio->hook_count;
	uint64_t *hook_sort=manio->hook_sort;
	if(!hook_sort) return 0;

	snprintf(msg, sizeof(msg), "%08"PRIX64, manio->offset->fcount-1);
	if(!(path=prepend_s(manio->hook_dir, msg))
	  || build_path_w(path)
	  || !(fzp=fzp_gzopen(path, MANIO_MODE_WRITE)))
		goto end;

	qsort(hook_sort, hook_count, sizeof(uint64_t), uint64_t_sort);

	if(write_hook_header(fzp, manio->rmanifest, msg)) goto end;
	for(i=0; i<hook_count; i++)
	{
		// Do not bother with duplicates.
		if(i && hook_sort[i]==hook_sort[i-1])
			continue;

		if(to_fzp_fingerprint(fzp, hook_sort[i]))
			goto end;
	}
	if(fzp_close(&fzp))
	{
		logp("Error closing %s in %s: %s\n",
			path, __func__, strerror(errno));
		goto end;
	}
	if(manio_write_fcount(manio)) goto end;
	manio->hook_count=0;
	ret=0;
end:
	fzp_close(&fzp);
	free_w(&path);
	return ret;
}
Beispiel #3
0
void build_sparse_index(const char *path, int manifests, int fingerprints)
{
	struct fzp *fzp;

	fail_unless(!build_path_w(path));

	fail_unless((fzp=fzp_gzopen(path, "wb"))!=NULL);
	for(int m=0; m<manifests; m++)
	{
		char mpath[256];
		snprintf(mpath, sizeof(mpath), "some/manifest/%d", m);
		fzp_printf(fzp, "%c%04lX%s\n",
			CMD_MANIFEST, strlen(mpath), mpath);

		for(int f=0; f<fingerprints; f++)
			fail_unless(!to_fzp_fingerprint(fzp, prng_next64()));
	}
	fail_unless(!fzp_close(&fzp));
}