diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2010-05-29 03:06:38 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2010-05-29 03:06:38 +0200 |
commit | d1b82557d266795621244c62644d4d0604cf5453 (patch) | |
tree | e2cf47e20689bc55236d5318c93a90627de3a7d7 /src | |
parent | 15a89a6d415191d998198e997cf4fc5b93c33985 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/browser.cpp | 30 |
1 files 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 += '/'; |