diff --git a/Glob.cxx b/Glob.cxx index 051813231fad108b6a2215a79dc0bd1edca6fdeb..bdda50e91ae6048e076e53a8a9fade4999c72a87 100644 --- a/Glob.cxx +++ b/Glob.cxx @@ -63,6 +63,10 @@ Glob::Glob() this->Internals = new GlobInternals; this->Recurse = false; this->Relative = ""; + + this->RecurseThroughSymlinks = true; + // RecurseThroughSymlinks is true by default for backwards compatibility, + // not because it's a good idea... } //---------------------------------------------------------------------------- @@ -262,7 +266,11 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, } if ( kwsys::SystemTools::FileIsDirectory(realname.c_str()) ) { - this->RecurseDirectory(start+1, realname, dir_only); + if (!kwsys::SystemTools::FileIsSymlink(realname.c_str()) || + this->RecurseThroughSymlinks) + { + this->RecurseDirectory(start+1, realname, dir_only); + } } } } diff --git a/Glob.hxx.in b/Glob.hxx.in index 9ede865b83e0d2db857a76d001a892e73d0cc368..f01f004b94d717146804b16708366140af9a23c8 100644 --- a/Glob.hxx.in +++ b/Glob.hxx.in @@ -57,6 +57,13 @@ public: void SetRecurse(bool i) { this->Recurse = i; } bool GetRecurse() { return this->Recurse; } + //! Set recurse through symlinks to true if recursion should traverse the + // linked-to directories + void RecurseThroughSymlinksOn() { this->SetRecurseThroughSymlinks(true); } + void RecurseThroughSymlinksOff() { this->SetRecurseThroughSymlinks(false); } + void SetRecurseThroughSymlinks(bool i) { this->RecurseThroughSymlinks = i; } + bool GetRecurseThroughSymlinks() { return this->RecurseThroughSymlinks; } + //! Set relative to true to only show relative path to files. void SetRelative(const char* dir); const char* GetRelative(); @@ -90,6 +97,7 @@ protected: GlobInternals* Internals; bool Recurse; kwsys_stl::string Relative; + bool RecurseThroughSymlinks; private: Glob(const Glob&); // Not implemented.