diff options
author | Max Kellermann <max@duempel.org> | 2014-02-28 19:02:23 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-03-01 06:25:57 +0100 |
commit | 96afa8bd2ba44d6669949db5fce4fee5f826b753 (patch) | |
tree | a484d32c412b2cb716cc149a42f702e8c3013f48 /src/db | |
parent | 797bbeabeb212ee3d818acdb19d85e2d8642f5ed (diff) | |
download | mpd-96afa8bd2ba44d6669949db5fce4fee5f826b753.tar.gz mpd-96afa8bd2ba44d6669949db5fce4fee5f826b753.tar.xz mpd-96afa8bd2ba44d6669949db5fce4fee5f826b753.zip |
command: add command "listfiles"
Lists files and directories. Supports storage plugins.
Diffstat (limited to '')
-rw-r--r-- | src/db/DatabasePrint.cxx | 69 | ||||
-rw-r--r-- | src/db/DatabasePrint.hxx | 3 |
2 files changed, 44 insertions, 28 deletions
diff --git a/src/db/DatabasePrint.cxx b/src/db/DatabasePrint.cxx index 0ffcad35e..c8ffa102f 100644 --- a/src/db/DatabasePrint.cxx +++ b/src/db/DatabasePrint.cxx @@ -29,29 +29,39 @@ #include "LightDirectory.hxx" #include "PlaylistInfo.hxx" #include "Interface.hxx" +#include "fs/Traits.hxx" #include <functional> +static const char * +ApplyBaseFlag(const char *uri, bool base) +{ + if (base) + uri = PathTraitsUTF8::GetBase(uri); + return uri; +} + static void -PrintDirectoryURI(Client &client, const LightDirectory &directory) +PrintDirectoryURI(Client &client, bool base, const LightDirectory &directory) { - client_printf(client, "directory: %s\n", directory.GetPath()); + client_printf(client, "directory: %s\n", + ApplyBaseFlag(directory.GetPath(), base)); } static bool -PrintDirectoryBrief(Client &client, const LightDirectory &directory) +PrintDirectoryBrief(Client &client, bool base, const LightDirectory &directory) { if (!directory.IsRoot()) - PrintDirectoryURI(client, directory); + PrintDirectoryURI(client, base, directory); return true; } static bool -PrintDirectoryFull(Client &client, const LightDirectory &directory) +PrintDirectoryFull(Client &client, bool base, const LightDirectory &directory) { if (!directory.IsRoot()) { - PrintDirectoryURI(client, directory); + PrintDirectoryURI(client, base, directory); if (directory.mtime > 0) time_print(client, "Last-Modified", directory.mtime); @@ -61,23 +71,24 @@ PrintDirectoryFull(Client &client, const LightDirectory &directory) } static void -print_playlist_in_directory(Client &client, +print_playlist_in_directory(Client &client, bool base, const char *directory, const char *name_utf8) { - if (directory == nullptr) - client_printf(client, "playlist: %s\n", name_utf8); + if (base || directory == nullptr) + client_printf(client, "playlist: %s\n", + ApplyBaseFlag(name_utf8, base)); else client_printf(client, "playlist: %s/%s\n", directory, name_utf8); } static void -print_playlist_in_directory(Client &client, +print_playlist_in_directory(Client &client, bool base, const LightDirectory *directory, const char *name_utf8) { - if (directory == nullptr || directory->IsRoot()) + if (base || directory == nullptr || directory->IsRoot()) client_printf(client, "playlist: %s\n", name_utf8); else client_printf(client, "playlist: %s/%s\n", @@ -85,44 +96,48 @@ print_playlist_in_directory(Client &client, } static bool -PrintSongBrief(Client &client, const LightSong &song) +PrintSongBrief(Client &client, bool base, const LightSong &song) { - song_print_uri(client, song); + song_print_uri(client, song, base); if (song.tag->has_playlist) /* this song file has an embedded CUE sheet */ - print_playlist_in_directory(client, song.directory, song.uri); + print_playlist_in_directory(client, base, + song.directory, song.uri); return true; } static bool -PrintSongFull(Client &client, const LightSong &song) +PrintSongFull(Client &client, bool base, const LightSong &song) { - song_print_info(client, song); + song_print_info(client, song, base); if (song.tag->has_playlist) /* this song file has an embedded CUE sheet */ - print_playlist_in_directory(client, song.directory, song.uri); + print_playlist_in_directory(client, base, + song.directory, song.uri); return true; } static bool -PrintPlaylistBrief(Client &client, +PrintPlaylistBrief(Client &client, bool base, const PlaylistInfo &playlist, const LightDirectory &directory) { - print_playlist_in_directory(client, &directory, playlist.name.c_str()); + print_playlist_in_directory(client, base, + &directory, playlist.name.c_str()); return true; } static bool -PrintPlaylistFull(Client &client, +PrintPlaylistFull(Client &client, bool base, const PlaylistInfo &playlist, const LightDirectory &directory) { - print_playlist_in_directory(client, &directory, playlist.name.c_str()); + print_playlist_in_directory(client, base, + &directory, playlist.name.c_str()); if (playlist.mtime > 0) time_print(client, "Last-Modified", playlist.mtime); @@ -132,7 +147,7 @@ PrintPlaylistFull(Client &client, bool db_selection_print(Client &client, const DatabaseSelection &selection, - bool full, Error &error) + bool full, bool base, Error &error) { const Database *db = client.GetDatabase(error); if (db == nullptr) @@ -141,13 +156,13 @@ db_selection_print(Client &client, const DatabaseSelection &selection, using namespace std::placeholders; const auto d = selection.filter == nullptr ? std::bind(full ? PrintDirectoryFull : PrintDirectoryBrief, - std::ref(client), _1) + std::ref(client), base, _1) : VisitDirectory(); const auto s = std::bind(full ? PrintSongFull : PrintSongBrief, - std::ref(client), _1); + std::ref(client), base, _1); const auto p = selection.filter == nullptr ? std::bind(full ? PrintPlaylistFull : PrintPlaylistBrief, - std::ref(client), _1, _2) + std::ref(client), base, _1, _2) : VisitPlaylist(); return db->Visit(selection, d, s, p, error); @@ -202,7 +217,7 @@ bool printAllIn(Client &client, const char *uri_utf8, Error &error) { const DatabaseSelection selection(uri_utf8, true); - return db_selection_print(client, selection, false, error); + return db_selection_print(client, selection, false, false, error); } bool @@ -210,7 +225,7 @@ printInfoForAllIn(Client &client, const char *uri_utf8, Error &error) { const DatabaseSelection selection(uri_utf8, true); - return db_selection_print(client, selection, true, error); + return db_selection_print(client, selection, true, false, error); } static bool diff --git a/src/db/DatabasePrint.hxx b/src/db/DatabasePrint.hxx index f336d9ff5..ef75dae36 100644 --- a/src/db/DatabasePrint.hxx +++ b/src/db/DatabasePrint.hxx @@ -29,10 +29,11 @@ class Error; /** * @param full print attributes/tags + * @param base print only base name of songs/directories? */ bool db_selection_print(Client &client, const DatabaseSelection &selection, - bool full, Error &error); + bool full, bool base, Error &error); gcc_nonnull(2) bool |