コード例 #1
0
ファイル: purge.c プロジェクト: sas/Droplet-backup
static void purge_file(storage_t storage, strset_t objects, char *hash)
{
  char *download_path;
  FILE *descr;
  char buf[4096];
  char *blob_hash;

  download_path = path_concat("objects", hash);
  if ((descr = storage_retrieve_file(storage, download_path)) == NULL)
    logger(LOG_ERROR, "unable to retrieve: %s", hash);
  free(download_path);

  while ((blob_hash = fgets(buf, 4096, descr)) != NULL)
  {
    size_t size;

    size = strlen(blob_hash);
    if (blob_hash[size - 1] != '\n')
      logger(LOG_ERROR, "invalid object: %s", hash);
    blob_hash[size - 1] = '\0';

    strset_del(objects, blob_hash);
  }

  if (ferror(descr))
    logger(LOG_ERROR, "unable to purge: %s", hash);

  fclose(descr);
}
コード例 #2
0
ファイル: purge.c プロジェクト: sas/Droplet-backup
static void purge_dispatch(storage_t storage, strset_t objects, char *elem_str)
{
  char *type;
  char *hash;

  if ((type = strsep(&elem_str, " ")) == NULL)
    logger(LOG_ERROR, "invalid description file: %s", elem_str);

  if ((hash = strsep(&elem_str, " ")) == NULL)
    logger(LOG_ERROR, "invalid description file: %s", elem_str);

  strset_del(objects, hash);

  if (strcmp(type, "file") == 0)
    purge_file(storage, objects, hash);
  else if (strcmp(type, "tree") == 0)
    purge_tree(storage, objects, hash);
  else if (strcmp(type, "link") == 0)
    return; /* No need to recurse. */
  else
    logger(LOG_ERROR, "invalid description file: %s", elem_str);
}
コード例 #3
0
ファイル: run.c プロジェクト: HSchroeder/ccan
int main(void)
{
	struct strset set;
	const char str[] = "hello";
	const char none[] = "";
	char *dup = strdup(str);

	/* This is how many tests you plan to run */
	plan_tests(36);

	strset_init(&set);

	ok1(!strset_get(&set, str));
	ok1(errno == ENOENT);
	ok1(!strset_get(&set, none));
	ok1(errno == ENOENT);
	ok1(!strset_del(&set, str));
	ok1(errno == ENOENT);
	ok1(!strset_del(&set, none));
	ok1(errno == ENOENT);

	ok1(strset_add(&set, str));
	ok1(strset_get(&set, str));
	/* We compare the string, not the pointer. */
	ok1(strset_get(&set, dup));
	ok1(!strset_get(&set, none));
	ok1(errno == ENOENT);

	/* Add of duplicate should fail. */
	ok1(!strset_add(&set, dup));
	ok1(errno == EEXIST);

	/* Delete should return original string. */
	ok1(strset_del(&set, dup) == str);
	ok1(!strset_get(&set, str));
	ok1(errno == ENOENT);
	ok1(!strset_get(&set, none));
	ok1(errno == ENOENT);

	/* Try insert and delete of empty string. */
	ok1(strset_add(&set, none));
	ok1(strset_get(&set, none));
	ok1(!strset_get(&set, str));
	ok1(errno == ENOENT);

	/* Delete should return original string. */
	ok1(strset_del(&set, "") == none);
	ok1(!strset_get(&set, str));
	ok1(errno == ENOENT);
	ok1(!strset_get(&set, none));
	ok1(errno == ENOENT);

	/* Both at once... */
	ok1(strset_add(&set, none));
	ok1(strset_add(&set, str));
	ok1(strset_get(&set, str));
	ok1(strset_get(&set, none));
	ok1(strset_del(&set, "") == none);
	ok1(strset_del(&set, dup) == str);

	ok1(set.u.n == NULL);
	free(dup);

	/* This exits depending on whether all tests passed */
	return exit_status();
}