| 51 | #endif |
| 52 | |
| 53 | CommandResult |
| 54 | handle_add(Client &client, Request args, [[maybe_unused]] Response &r) |
| 55 | { |
| 56 | auto &partition = client.GetPartition(); |
| 57 | |
| 58 | const char *uri = args.front(); |
| 59 | if (StringIsEqual(uri, "/")) |
| 60 | /* this URI is malformed, but some clients are buggy |
| 61 | and use "add /" to add the whole database, which |
| 62 | was never intended to work, but once did; in order |
| 63 | to retain backwards compatibility, work around this |
| 64 | here */ |
| 65 | uri = ""; |
| 66 | |
| 67 | const auto old_size = partition.playlist.GetLength(); |
| 68 | const unsigned position = args.size() > 1 |
| 69 | ? ParseInsertPosition(args[1], partition.playlist) |
| 70 | : old_size; |
| 71 | |
| 72 | const auto located_uri = LocateUri(UriPluginKind::INPUT, uri, |
| 73 | &client, |
| 74 | #ifdef ENABLE_DATABASE |
| 75 | nullptr, |
| 76 | #endif |
| 77 | true); |
| 78 | switch (located_uri.type) { |
| 79 | case LocatedUri::Type::ABSOLUTE: |
| 80 | AddUri(client, located_uri); |
| 81 | client.GetInstance().LookupRemoteTag(located_uri.canonical_uri); |
| 82 | break; |
| 83 | |
| 84 | case LocatedUri::Type::PATH: |
| 85 | AddUri(client, located_uri); |
| 86 | break; |
| 87 | |
| 88 | case LocatedUri::Type::RELATIVE: |
| 89 | #ifdef ENABLE_DATABASE |
| 90 | AddDatabaseSelection(partition, located_uri.canonical_uri); |
| 91 | break; |
| 92 | #else |
| 93 | r.Error(ACK_ERROR_NO_EXIST, "No database"); |
| 94 | return CommandResult::ERROR; |
| 95 | #endif |
| 96 | } |
| 97 | |
| 98 | if (position < old_size) { |
| 99 | const unsigned new_size = partition.playlist.GetLength(); |
| 100 | const RangeArg move_range{old_size, new_size}; |
| 101 | |
| 102 | try { |
| 103 | partition.MoveRange(move_range, position); |
| 104 | } catch (...) { |
| 105 | /* ignore - shall we handle it? */ |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return CommandResult::OK; |
| 110 | } |
nothing calls this directly
no test coverage detected