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.
This commit is contained in:
Andrzej Rybczak
2010-05-29 03:06:38 +02:00
parent 15a89a6d41
commit d1b82557d2

View File

@@ -426,20 +426,13 @@ void Browser::GetLocalDirectory(MPD::ItemList &v, const std::string &directory,
struct stat file_stat; struct stat file_stat;
std::string full_path; 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(); size_t old_size = v.size();
while ((file = readdir(dir))) 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] == '.') if (!Config.local_browser_show_hidden_files && file->d_name[0] == '.')
continue; continue;
MPD::Item new_item; MPD::Item new_item;
@@ -488,19 +481,12 @@ void Browser::ClearDirectory(const std::string &path) const
struct stat file_stat; struct stat file_stat;
std::string full_path; 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))) 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; full_path = path;
if (*full_path.rbegin() != '/') if (*full_path.rbegin() != '/')
full_path += '/'; full_path += '/';