示例#1
0
	void test(struct meta2_backend_s *m2, struct hc_url_s *url) {
		GError *err;
		/* Generate a list of beans */
		GSList *beans = create_alias(m2, url, NULL);
		/* Change the hash of the chunk beans (0 by default) */
		change_chunk_hash(beans, 0);
		/* Put the beans in the database */
		err = meta2_backend_put_alias(m2, url, beans, NULL, NULL);
		g_assert_no_error(err);
		_bean_cleanl2(beans);

		/* Generate other contents with same hashes */
		for (guint counter = 1; counter <= num_duplicates; counter++) {
			/* Suffix the base url */
			gchar *url_str = g_strdup_printf("%s_%d", hc_url_get(url, HCURL_WHOLE),
					counter);
			struct hc_url_s *url2 = hc_url_oldinit(url_str);
			g_free(url_str);
			GSList *beans2 = create_alias(m2, url2, NULL);
			change_chunk_hash(beans2, counter);
			err = meta2_backend_put_alias(m2, url2, beans2, NULL, NULL);
			g_assert_no_error(err);
			_bean_cleanl2(beans2);
		}

		err = meta2_backend_deduplicate_chunks(m2, url);
		g_assert_no_error(err);
	}
示例#2
0
int		setting_42sh(t_shell *sh, char **argv, char **env)
{
  sh->ret = 0;
  sh->env = cpy_env(env);
  fill_history(sh);
  create_alias(sh);
  create_oldpwd(sh);
  create_set(sh);
  if (options(argv, sh))
    return (0);
  return (1);
}
示例#3
0
/**
 * Create alias data from Aliases file
 *
 * \param filename  The path to the Aliases file
 * \return 1 on success, 0 on failure.
 */
int create_alias_data(const char *filename)
{
	char buf[300];
	FILE *fp;

	if (!filename)
		return 0;

	fp = fopen(filename, "r");
	if (!fp)
		return 0;

	while (fgets(buf, sizeof buf, fp)) {
		char *p, *aliases = 0, *mib, *end;
		struct canon *cf;

		if (buf[0] == 0 || buf[0] == '#')
			/* skip blank lines or comments */
			continue;

		buf[strlen(buf) - 1] = 0; /* lose terminating newline */
		end = buf + strlen(buf);

		/* find end of canonical form */
		for (p = buf; *p && !isspace(*p) && !iscntrl(*p); p++)
			; /* do nothing */
		if (p >= end)
			continue;
		*p++ = '\0'; /* terminate canonical form */

		/* skip whitespace */
		for (; *p && isspace(*p); p++)
			; /* do nothing */
		if (p >= end)
			continue;
		mib = p;

		/* find end of mibenum */
		for (; *p && !isspace(*p) && !iscntrl(*p); p++)
			; /* do nothing */
		if (p < end)
			*p++ = '\0'; /* terminate mibenum */

		cf = create_canon(buf, atoi(mib));
		if (!cf)
			continue;

		/* skip whitespace */
		for (; p < end && *p && isspace(*p); p++)
			; /* do nothing */
		if (p >= end)
			continue;
		aliases = p;

		while (p < end) {
			/* find end of alias */
			for (; *p && !isspace(*p) && !iscntrl(*p); p++)
				; /* do nothing */
			if (p > end)
				/* stop if we've gone past the end */
				break;
			/* terminate current alias */
			*p++ = '\0';

			if (!create_alias(aliases, cf))
				break;

			/* in terminating, we may have advanced
			 * past the end - check this here */
			if (p >= end)
				break;

			/* skip whitespace */
			for (; *p && isspace(*p); p++)
				; /* do nothing */

			if (p >= end)
				/* gone past end => stop */
				break;

			/* update pointer to current alias */
			aliases = p;
		}
	}

	fclose(fp);

	return 1;
}