Esempio n. 1
0
int cmd_purge(int argc, char *argv[])
{
  storage_t storage;
  strset_t backups;
  strset_t objects;
  const char *elem;
  struct mark_backup_args args;

  if (argc != 2)
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "purge", NULL };
    return cmd_help_err(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], false, true)) == NULL)
    logger(LOG_ERROR, "unable to open storage: %s", argv[1]);

  if (!storage_lock(storage, true, options_get()->force))
    logger(LOG_ERROR, "backup directory locked, use -f to force operation");

  backups = strset_new();
  objects = strset_new();

  /* Get the list of backups. */
  elem = storage_list(storage, "backups");
  while (elem != NULL)
  {
    strset_add(backups, elem);
    elem = storage_list(storage, NULL);
  }

  /* Get the list of objects. */
  elem = storage_list(storage, "objects");
  while (elem != NULL)
  {
    strset_add(objects, elem);
    elem = storage_list(storage, NULL);
  }

  /*
  ** For each backup, call mark_backup, which will mark all the objects of a
  ** backup as used (it will actually remove them from the `objects` strset.
  */
  args.objects = objects;
  args.storage = storage;
  strset_foreach(backups, mark_backup, &args);

  /* Delete every object remaining in the `objects` strset. */
  strset_foreach(objects, delete_object, (void *) storage);

  strset_delete(backups);
  strset_delete(objects);
  storage_unlock(storage);
  storage_delete(storage);

  return EXIT_SUCCESS;
}
Esempio n. 2
0
int listAllUniqueTags(struct client *client, int type,
		      const struct locate_item_list *criteria)
{
	int ret;
	ListCommandItem *item = newListCommandItem(type, criteria);
	struct list_tags_data data = {
		.client = client,
		.item = item,
	};

	if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
		data.set = strset_new();
	}

	ret = db_walk(NULL, listUniqueTagsInDirectory, NULL, &data);

	if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
		const char *value;

		strset_rewind(data.set);

		while ((value = strset_next(data.set)) != NULL)
			client_printf(client, "%s: %s\n",
				      tag_item_names[type],
				      value);

		strset_free(data.set);
	}

	freeListCommandItem(item);

	return ret;
}
Esempio n. 3
0
void stats_update(void)
{
    struct visit_data data;

    stats.song_count = 0;
    stats.song_duration = 0;
    stats.artist_count = 0;

    data.artists = strset_new();
    data.albums = strset_new();

    db_walk(NULL, stats_collect_song, NULL, &data);

    stats.artist_count = strset_size(data.artists);
    stats.album_count = strset_size(data.albums);

    strset_free(data.artists);
    strset_free(data.albums);
}
Esempio n. 4
0
bool
listAllUniqueTags(struct client *client, int type,
		  const struct locate_item_list *criteria,
		  GError **error_r)
{
	ListCommandItem *item = newListCommandItem(type, criteria);
	struct list_tags_data data = {
		.client = client,
		.item = item,
	};

	if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
		data.set = strset_new();
	}

	if (!db_walk("", &unique_tags_visitor, &data, error_r)) {
		freeListCommandItem(item);
		return false;
	}

	if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
		const char *value;

		strset_rewind(data.set);

		while ((value = strset_next(data.set)) != NULL)
			client_printf(client, "%s: %s\n",
				      tag_item_names[type],
				      value);

		strset_free(data.set);
	}

	freeListCommandItem(item);

	return true;
}
Esempio n. 5
0
int main() {
    unsigned long s1, s2, s3;

    s1 = strset_new();
    strset_insert(s1, "foo");
    assert(strset_test(s1, "foo"));
    assert(!strset_test(s1, "bar"));
    strset_insert(s1, "bar");
    assert(strset_test(s1, "bar"));
    assert(strset_size(s1) == 2);
    strset_insert(s1, "bar");
    assert(strset_size(s1) == 2);
    strset_remove(s1, "foo");
    assert(!strset_test(s1, "foo"));
    assert(strset_test(s1, "bar"));
    assert(strset_size(s1) == 1);

    strset_delete(s1);
    strset_insert(s1, "whatever");
    assert(strset_size(s1) == 0);
    assert(!strset_test(s1, "whatever"));

    s2 = strset_new();
    s3 = strset_new();
    strset_insert(s2, "Ania");
    strset_insert(s2, "Alek");
    strset_insert(s2, "Maria");
    strset_insert(s2, "Fiona");
    strset_insert(s3, "Ania");
    strset_insert(s3, "Maria");
    assert(strset_comp(s2, s3) == -1);
    assert(strset_comp(s3, s2) == 1);
    strset_remove(s2, "Alek");
    strset_remove(s2, "Fiona");
    strset_remove(s2, "Olek");
    assert(strset_comp(s3, s2) == 0);
    strset_clear(s3);
    assert(strset_comp(s2, s3) == 1);
    strset_clear(s2);
    assert(strset_comp(s2, s3) == 0);
    strset_delete(s2);
    strset_delete(s3);
    assert(strset_comp(s2, s3) == 0);

    assert(strset_size(strset42()) == 1);
    strset_delete(strset42());
    strset_insert(strset42(), "66");
    assert(strset_size(strset42()) == 1);
    strset_insert(strset42(), "24");
    strset_insert(strset42(), "42");
    assert(!strset_test(strset42(), "24"));
    assert(strset_test(strset42(), "42"));
    strset_remove(strset42(), "42");
    assert(strset_size(strset42()) == 1);
    strset_clear(strset42());
    assert(strset_size(strset42()) == 1);
    assert(strset_comp(strset42(), strset42()) == 0);
    assert(strset_comp(strset42(), 666) == 1);
    assert(strset_comp(666, strset42()) == -1);

    return 0;
}