Esempio n. 1
0
static int deduplicate_maybe(struct asfd *asfd,
	struct blk *blk, const char *directory, struct scores *scores)
{
	if(!asfd->in && !(asfd->in=incoming_alloc()))
		return -1;

	if(blk_fingerprint_is_hook(blk))
	{
		if(incoming_grow_maybe(asfd->in))
			return -1;
		asfd->in->fingerprints[asfd->in->size-1]=blk->fingerprint;
	}
	if(++(asfd->blkcnt)<MANIFEST_SIG_MAX)
		return 0;
	asfd->blkcnt=0;

	if(deduplicate(asfd, directory, scores)<0)
		return -1;

	return 0;
}
Esempio n. 2
0
int manio_write_sig_and_path(struct manio *manio, struct blk *blk)
{
	if(manio->protocol==PROTO_1) return 0;
	if(manio->hook_sort && blk_fingerprint_is_hook(blk))
	{
		// Add to list of hooks for this manifest chunk.
		manio->hook_sort[manio->hook_count++]=blk->fingerprint;
	}
	if(manio->dindex_sort)
	{
		uint64_t savepath=blk->savepath;
		savepath &= 0xFFFFFFFFFFFF0000;
		// Ignore obvious duplicates.
		if(!manio->dindex_count
		  || manio->dindex_sort[manio->dindex_count-1]!=savepath)
		{
			// Add to list of dindexes for this manifest chunk.
			manio->dindex_sort[manio->dindex_count++]=savepath;
		}
	}
	return write_sig_msg(manio, blk);
}
Esempio n. 3
0
// This deals with reading in the sparse index, as well as actual candidate
// manifests.
enum cand_ret candidate_load(struct candidate *candidate, const char *path,
	struct scores *scores)
{
	enum cand_ret ret=CAND_RET_PERM;
	struct fzp *fzp=NULL;
	struct sbuf *sb=NULL;
	struct blk *blk=NULL;

	if(!(sb=sbuf_alloc(PROTO_2))
	  || !(blk=blk_alloc()))
	{
		ret=CAND_RET_PERM;
		goto error;
	}
	
	if(!(fzp=fzp_gzopen(path, "rb")))
	{
		ret=CAND_RET_TEMP;
		goto error;
	}
	while(fzp)
	{
		sbuf_free_content(sb);
		switch(sbuf_fill_from_file(sb, fzp, blk, NULL))
		{
			case 1: goto end;
			case -1:
				logp("Error reading %s in %s, pos %d\n",
					path, __func__, fzp_tell(fzp));
				ret=CAND_RET_TEMP;
				goto error;
		}
		if(blk_fingerprint_is_hook(blk))
		{
			if(sparse_add_candidate(&blk->fingerprint, candidate))
			{
				ret=CAND_RET_PERM;
				goto error;
			}
		}
		else if(sb->path.cmd==CMD_MANIFEST)
		{
			if(!(candidate=candidates_add_new()))
			{
				ret=CAND_RET_PERM;
				goto error;
			}
			candidate->path=sb->path.buf;
			sb->path.buf=NULL;
		}
		blk->fingerprint=0;
	}

end:
	if(scores_grow(scores, candidates_len))
	{
		ret=CAND_RET_PERM;
		goto error;
	}
	candidates_set_score_pointers(candidates, candidates_len, scores);
	scores_reset(scores);
	//logp("Now have %d candidates\n", (int)candidates_len);
	ret=CAND_RET_OK;
error:
	fzp_close(&fzp);
	sbuf_free(&sb);
	blk_free(&blk);
	return ret;
}