aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-09 23:37:34 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-09 23:37:34 +0000
commit48a080a327e7b1541f08ae94dca14b716888bed3 (patch)
tree9d90cc2304fe4f6f1d861dcbb3531765fa75cf08
parent4ca826151e36bf699a8f01ba2ec0c70f548de02d (diff)
downloadpaludis-48a080a327e7b1541f08ae94dca14b716888bed3.tar.gz
paludis-48a080a327e7b1541f08ae94dca14b716888bed3.tar.xz
Make dotfile ignoration an option
-rw-r--r--paludis/util/dir_iterator.cc13
-rw-r--r--paludis/util/dir_iterator.hh6
-rw-r--r--paludis/util/dir_iterator_TEST.cc25
-rwxr-xr-xpaludis/util/dir_iterator_TEST_setup.sh2
4 files changed, 37 insertions, 9 deletions
diff --git a/paludis/util/dir_iterator.cc b/paludis/util/dir_iterator.cc
index e651c79..da97dc3 100644
--- a/paludis/util/dir_iterator.cc
+++ b/paludis/util/dir_iterator.cc
@@ -36,8 +36,9 @@ DirOpenError::DirOpenError(const FSEntry & location, const int errno_value) thro
{
}
-DirIterator::DirIterator(const FSEntry & base) :
+DirIterator::DirIterator(const FSEntry & base, bool ignore_dotfiles) :
_base(base),
+ _ignore_dotfiles(ignore_dotfiles),
_items(new std::set<FSEntry>)
{
DIR * d(opendir(stringify(base).c_str()));
@@ -46,8 +47,15 @@ DirIterator::DirIterator(const FSEntry & base) :
struct dirent * de;
while (0 != ((de = readdir(d))))
- if ('.' != de->d_name[0])
+ if (ignore_dotfiles)
+ {
+ if ('.' != de->d_name[0])
+ _items->insert(_base / std::string(de->d_name));
+ }
+ else if (! (de->d_name[0] == '.' &&
+ (de->d_name[1] == '\0' || (de->d_name[1] == '.' && de->d_name[2] == '\0'))))
_items->insert(_base / std::string(de->d_name));
+
_iter = _items->begin();
closedir(d);
@@ -55,6 +63,7 @@ DirIterator::DirIterator(const FSEntry & base) :
DirIterator::DirIterator(const DirIterator & other) :
_base(other._base),
+ _ignore_dotfiles(other._ignore_dotfiles),
_items(other._items),
_iter(other._iter)
{
diff --git a/paludis/util/dir_iterator.hh b/paludis/util/dir_iterator.hh
index 08d16e2..023a7ed 100644
--- a/paludis/util/dir_iterator.hh
+++ b/paludis/util/dir_iterator.hh
@@ -61,14 +61,16 @@ namespace paludis
{
private:
FSEntry _base;
+ bool _ignore_dotfiles;
CountedPtr<std::set<FSEntry>, count_policy::ExternalCountTag> _items;
std::set<FSEntry>::iterator _iter;
public:
/**
- * Constructor, to an FSEntry which must be a directory.
+ * Constructor, to an FSEntry which must be a directory, with an
+ * option to not ignore dotfiles.
*/
- explicit DirIterator(const FSEntry & base);
+ explicit DirIterator(const FSEntry & base, bool ignore_dotfiles = true);
/**
* Copy constructor.
diff --git a/paludis/util/dir_iterator_TEST.cc b/paludis/util/dir_iterator_TEST.cc
index 3b1c4ed..022e0cf 100644
--- a/paludis/util/dir_iterator_TEST.cc
+++ b/paludis/util/dir_iterator_TEST.cc
@@ -61,16 +61,33 @@ namespace test_cases
{
DirIterator iter(FSEntry("dir_iterator_TEST_dir"));
DirIterator iter1(FSEntry("dir_iterator_TEST_dir"));
+ DirIterator iter2(FSEntry("dir_iterator_TEST_dir"), false);
TEST_CHECK(iter != DirIterator());
TEST_CHECK(DirIterator() != iter);
- TEST_CHECK(*iter == FSEntry("dir_iterator_TEST_dir/all_perms"));
- TEST_CHECK(*(iter++) == FSEntry("dir_iterator_TEST_dir/all_perms"));
- TEST_CHECK(iter == DirIterator());
+ TEST_CHECK_EQUAL(iter->basename(), "file1");
+ TEST_CHECK(++iter != DirIterator());
+ TEST_CHECK_EQUAL(iter->basename(), "file2");
+ TEST_CHECK(++iter == DirIterator());
TEST_CHECK(DirIterator() == iter);
- TEST_CHECK(++iter1 == DirIterator());
+ while (iter1 != DirIterator())
+ ++iter1;
+ TEST_CHECK(iter1 == DirIterator());
+ TEST_CHECK(iter == iter1);
+
+ TEST_CHECK_EQUAL(iter2->basename(), ".file3");
+ TEST_CHECK(++iter2 != DirIterator());
+ TEST_CHECK_EQUAL(iter2->basename(), "file1");
+ TEST_CHECK(++iter2 != DirIterator());
+ TEST_CHECK_EQUAL(iter2->basename(), "file2");
+ TEST_CHECK(++iter2 == DirIterator());
+ TEST_CHECK(DirIterator() == iter2);
+ TEST_CHECK(iter2 == DirIterator());
+
+ TEST_CHECK(iter1 == iter2);
+ TEST_CHECK(iter2 == iter1);
}
} test_dir_iterator_iterate;
}
diff --git a/paludis/util/dir_iterator_TEST_setup.sh b/paludis/util/dir_iterator_TEST_setup.sh
index 9fa425e..7ddb62b 100755
--- a/paludis/util/dir_iterator_TEST_setup.sh
+++ b/paludis/util/dir_iterator_TEST_setup.sh
@@ -3,4 +3,4 @@
mkdir dir_iterator_TEST_dir || exit 2
cd dir_iterator_TEST_dir || exit 3
-touch all_perms || exit 4
+touch file1 file2 .file3 || exit 4