browser: properly report errors when deleting items fails
This commit is contained in:
@@ -672,15 +672,15 @@ void DeleteBrowserItems::run()
|
||||
{
|
||||
const MPD::Item &i = (*it)->value();
|
||||
std::string iname = i.type == MPD::itSong ? i.song->getName() : i.name;
|
||||
if (myBrowser->deleteItem(i))
|
||||
std::string errmsg;
|
||||
if (myBrowser->deleteItem(i, errmsg))
|
||||
{
|
||||
const char msg[] = "\"%ls\" deleted";
|
||||
Statusbar::msg(msg, wideShorten(ToWString(iname), COLS-const_strlen(msg)).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
const char msg[] = "Couldn't delete \"%ls\": %s";
|
||||
Statusbar::msg(msg, wideShorten(ToWString(iname), COLS-const_strlen(msg)-25).c_str(), strerror(errno));
|
||||
Statusbar::msg("%s", errmsg.c_str());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ struct Browser: Screen<NC::Menu<MPD::Item>>, Filterable, HasSongs, Searchable, T
|
||||
void GetLocalDirectory(MPD::ItemList &, const std::string &, bool) const;
|
||||
void ClearDirectory(const std::string &) const;
|
||||
void ChangeBrowseMode();
|
||||
bool deleteItem(const MPD::Item &);
|
||||
bool deleteItem(const MPD::Item &, std::string &errmsg);
|
||||
# endif // !WIN32
|
||||
|
||||
static bool isParentDirectory(const MPD::Item &item) {
|
||||
|
||||
Reference in New Issue
Block a user