browser: properly report errors when deleting items fails

master
Andrzej Rybczak 12 years ago
parent d28dcf6781
commit 8913c77786
  1. 6
      src/actions.cpp
  2. 24
      src/browser.cpp
  3. 2
      src/browser.h

@ -672,15 +672,15 @@ void DeleteBrowserItems::run()
{ {
const MPD::Item &i = (*it)->value(); const MPD::Item &i = (*it)->value();
std::string iname = i.type == MPD::itSong ? i.song->getName() : i.name; 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"; const char msg[] = "\"%ls\" deleted";
Statusbar::msg(msg, wideShorten(ToWString(iname), COLS-const_strlen(msg)).c_str()); Statusbar::msg(msg, wideShorten(ToWString(iname), COLS-const_strlen(msg)).c_str());
} }
else else
{ {
const char msg[] = "Couldn't delete \"%ls\": %s"; Statusbar::msg("%s", errmsg.c_str());
Statusbar::msg(msg, wideShorten(ToWString(iname), COLS-const_strlen(msg)-25).c_str(), strerror(errno));
success = false; success = false;
break; break;
} }

@ -541,7 +541,7 @@ void Browser::ChangeBrowseMode()
drawHeader(); drawHeader();
} }
bool Browser::deleteItem(const MPD::Item &item) bool Browser::deleteItem(const MPD::Item &item, std::string &errmsg)
{ {
if (isParentDirectory((item))) if (isParentDirectory((item)))
FatalError("Parent directory passed to Browser::deleteItem"); FatalError("Parent directory passed to Browser::deleteItem");
@ -555,10 +555,28 @@ bool Browser::deleteItem(const MPD::Item &item)
path = Config.mpd_music_dir; path = Config.mpd_music_dir;
path += item.type == itSong ? item.song->getURI() : item.name; path += item.type == itSong ? item.song->getURI() : item.name;
bool rv;
try
{
if (item.type == itDirectory) if (item.type == itDirectory)
ClearDirectory(path); ClearDirectory(path);
if (!boost::filesystem::exists(path))
return std::remove(path.c_str()) == 0; {
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 #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 GetLocalDirectory(MPD::ItemList &, const std::string &, bool) const;
void ClearDirectory(const std::string &) const; void ClearDirectory(const std::string &) const;
void ChangeBrowseMode(); void ChangeBrowseMode();
bool deleteItem(const MPD::Item &); bool deleteItem(const MPD::Item &, std::string &errmsg);
# endif // !WIN32 # endif // !WIN32
static bool isParentDirectory(const MPD::Item &item) { static bool isParentDirectory(const MPD::Item &item) {

Loading…
Cancel
Save