browser: properly report errors when deleting items fails

This commit is contained in:
Andrzej Rybczak
2014-04-26 17:53:59 +02:00
parent d28dcf6781
commit 8913c77786
3 changed files with 27 additions and 9 deletions

View File

@@ -541,7 +541,7 @@ void Browser::ChangeBrowseMode()
drawHeader();
}
bool Browser::deleteItem(const MPD::Item &item)
bool Browser::deleteItem(const MPD::Item &item, std::string &errmsg)
{
if (isParentDirectory((item)))
FatalError("Parent directory passed to Browser::deleteItem");
@@ -555,10 +555,28 @@ bool Browser::deleteItem(const MPD::Item &item)
path = Config.mpd_music_dir;
path += item.type == itSong ? item.song->getURI() : item.name;
if (item.type == itDirectory)
ClearDirectory(path);
return std::remove(path.c_str()) == 0;
bool rv;
try
{
if (item.type == itDirectory)
ClearDirectory(path);
if (!boost::filesystem::exists(path))
{
errmsg = "No such item: " + path;
rv = false;
}
else
{
boost::filesystem::remove(path);
rv = true;
}
}
catch (boost::filesystem::filesystem_error &err)
{
errmsg = err.what();
rv = false;
}
return rv;
}
#endif // !WIN32