summaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
authorAndrzej Rybczak <electricityispower@gmail.com>2013-05-16 21:31:05 +0200
committerAndrzej Rybczak <electricityispower@gmail.com>2013-05-16 21:32:47 +0200
commit5dca3eb8b59acf2e90cf09c4f2406b4c28c1d578 (patch)
treea9807bd8579a8b47649be7dff05d01e4dfed8dad /src/browser.cpp
parent56bf829b999eed274876e2752c43c40c1452f4d2 (diff)
browser: use boost::filesystem for clearing directories
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp41
1 files changed, 9 insertions, 32 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index ecb16555..6cc8efc5 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -513,39 +513,16 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory,
void Browser::ClearDirectory(const std::string &path) const
{
- DIR *dir = opendir(path.c_str());
- if (!dir)
- return;
-
- dirent *file;
- struct stat file_stat;
- std::string full_path;
+ namespace fs = boost::filesystem;
- while ((file = readdir(dir)))
- {
- // omit . and ..
- 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);
+ fs::path dir(path);
+ std::for_each(fs::directory_iterator(dir), fs::directory_iterator(), [&](fs::directory_entry &e) {
+ if (!fs::is_symlink(e) && fs::is_directory(e))
+ ClearDirectory(e.path().native());
+ const char msg[] = "Deleting \"%ls\"...";
+ Statusbar::msg(msg, wideShorten(ToWString(e.path().native()), COLS-const_strlen(msg)).c_str());
+ fs::remove(e.path());
+ });
}
void Browser::ChangeBrowseMode()