browser: use boost::filesystem for clearing directories
This commit is contained in:
@@ -513,39 +513,16 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory,
|
|||||||
|
|
||||||
void Browser::ClearDirectory(const std::string &path) const
|
void Browser::ClearDirectory(const std::string &path) const
|
||||||
{
|
{
|
||||||
DIR *dir = opendir(path.c_str());
|
namespace fs = boost::filesystem;
|
||||||
if (!dir)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dirent *file;
|
fs::path dir(path);
|
||||||
struct stat file_stat;
|
std::for_each(fs::directory_iterator(dir), fs::directory_iterator(), [&](fs::directory_entry &e) {
|
||||||
std::string full_path;
|
if (!fs::is_symlink(e) && fs::is_directory(e))
|
||||||
|
ClearDirectory(e.path().native());
|
||||||
while ((file = readdir(dir)))
|
const char msg[] = "Deleting \"%ls\"...";
|
||||||
{
|
Statusbar::msg(msg, wideShorten(ToWString(e.path().native()), COLS-const_strlen(msg)).c_str());
|
||||||
// omit . and ..
|
fs::remove(e.path());
|
||||||
if (file->d_name[0] == '.' && (file->d_name[1] == '\0' || (file->d_name[1] == '.' && file->d_name[2] == '\0')))
|
});
|
||||||
continue;
|
|
||||||
|
|
||||||
full_path = path;
|
|
||||||
if (*full_path.rbegin() != '/')
|
|
||||||
full_path += '/';
|
|
||||||
full_path += file->d_name;
|
|
||||||
lstat(full_path.c_str(), &file_stat);
|
|
||||||
if (S_ISDIR(file_stat.st_mode))
|
|
||||||
ClearDirectory(full_path);
|
|
||||||
if (remove(full_path.c_str()) == 0)
|
|
||||||
{
|
|
||||||
const char msg[] = "Deleting \"%ls\"...";
|
|
||||||
Statusbar::msg(msg, wideShorten(ToWString(full_path), COLS-const_strlen(msg)).c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const char msg[] = "Couldn't remove \"%ls\": %s";
|
|
||||||
Statusbar::msg(msg, wideShorten(ToWString(full_path), COLS-const_strlen(msg)-25).c_str(), strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::ChangeBrowseMode()
|
void Browser::ChangeBrowseMode()
|
||||||
|
|||||||
Reference in New Issue
Block a user