db: fix broken command "list ... group"

Grouping in the "list" command was completely broken from the start,
unlike "count group".  I have no idea what I have been thinking when I
wrote commit ae178c77bd, but it didn't
make any sense.

This commit is a rewrite of the feature.

For clients to be able to detect this feature, this commit also
increments the protocol version.
This commit is contained in:
Max Kellermann
2018-10-22 11:35:22 +02:00
parent 7cfe929c36
commit db27bb76e2
15 changed files with 145 additions and 332 deletions

View File

@@ -191,7 +191,7 @@ handle_list(Client &client, Request args, Response &r)
}
std::unique_ptr<SongFilter> filter;
tag_mask_t group_mask = 0;
TagType group = TAG_NUM_OF_ITEM_TYPES;
if (args.size == 1) {
/* for compatibility with < 0.12.0 */
@@ -206,18 +206,16 @@ handle_list(Client &client, Request args, Response &r)
args.shift()));
}
while (args.size >= 2 &&
StringIsEqual(args[args.size - 2], "group")) {
if (args.size >= 2 &&
StringIsEqual(args[args.size - 2], "group")) {
const char *s = args[args.size - 1];
TagType gt = tag_name_parse_i(s);
if (gt == TAG_NUM_OF_ITEM_TYPES) {
group = tag_name_parse_i(s);
if (group == TAG_NUM_OF_ITEM_TYPES) {
r.FormatError(ACK_ERROR_ARG,
"Unknown tag type: %s", s);
return CommandResult::ERROR;
}
group_mask |= tag_mask_t(1) << unsigned(gt);
args.pop_back();
args.pop_back();
}
@@ -230,14 +228,13 @@ handle_list(Client &client, Request args, Response &r)
}
}
if (tagType < TAG_NUM_OF_ITEM_TYPES &&
group_mask & (tag_mask_t(1) << tagType)) {
if (tagType < TAG_NUM_OF_ITEM_TYPES && tagType == group) {
r.Error(ACK_ERROR_ARG, "Conflicting group");
return CommandResult::ERROR;
}
PrintUniqueTags(r, client.partition,
tagType, group_mask, filter.get());
tagType, group, filter.get());
return CommandResult::OK;
}