Esempio n. 1
0
// When a backup is ongoing, use this to add newly complete candidates.
int candidate_add_fresh(const char *path, const char *directory,
	struct scores *scores)
{
	const char *cp=NULL;
	struct candidate *candidate=NULL;

	if(!(candidate=candidates_add_new()))
		goto error;
	cp=path+strlen(directory);
	while(cp && *cp=='/') cp++;
	if(!(candidate->path=strdup_w(cp, __func__)))
		goto error;

	switch(candidate_load(candidate, path, scores))
	{
		case CAND_RET_PERM:
			goto error;
		case CAND_RET_TEMP:
			// Had an error - try to carry on. Errors can happen
			// when loading a fresh candidate because the backup
			// process can move to the next phase and rename the
			// candidates.
			logp("Removing candidate.\n");
			candidates_len--;
			sparse_delete_fresh_candidate(candidate);
			candidate_free(&candidate);
			// Fall through.
		case CAND_RET_OK:
			return 0;
	}
error:
	candidate_free(&candidate);
	return -1;
}
Esempio n. 2
0
int champ_chooser_init(const char *datadir, struct conf *conf)
{
	int ret=-1;
	struct stat statp;
	char *sparse_path=NULL;

	// FIX THIS: scores is a global variable.
	if(!scores && !(scores=scores_alloc())) goto end;

	if(!(sparse_path=prepend_s(datadir, "sparse"))) goto end;
	if(lstat(sparse_path, &statp))
	{
		ret=0;
		goto end;
	}
	ret=candidate_load(NULL, sparse_path, conf);
end:
	if(sparse_path) free(sparse_path);
	return ret;
}