From d1b82557d266795621244c62644d4d0604cf5453 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 29 May 2010 03:06:38 +0200 Subject: [PATCH] browser: fix omitting . and .. in Browser::{Clear,GetLocal}Directory it seems that sometimes . and .. are not the first ones in directory structure, so check for them in main loop rather than in separate one at the beginning. attention! this fix is critical for people who use function that removes physically directories from hdd with ncmpcpp. --- src/browser.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/browser.cpp b/src/browser.cpp index cdb87c90..99adb815 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -426,20 +426,13 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory, struct stat file_stat; std::string full_path; - // omit . and .. - for (int i = 0; i < 2; ++i) - { - file = readdir(dir); - if (!file) - { - closedir(dir); - return; - } - } - size_t old_size = v.size(); 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; + if (!Config.local_browser_show_hidden_files && file->d_name[0] == '.') continue; MPD::Item new_item; @@ -488,19 +481,12 @@ void Browser::ClearDirectory(const std::string &path) const struct stat file_stat; std::string full_path; - // omit . and .. - for (int i = 0; i < 2; ++i) - { - file = readdir(dir); - if (!file) - { - closedir(dir); - return; - } - } - 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 += '/';