From 527a40f06fc7f0ea6aa9c1fe96fb0fe5611fa633 Mon Sep 17 00:00:00 2001 From: David Cole <david.cole@kitware.com> Date: Tue, 6 Sep 2011 13:12:03 -0400 Subject: [PATCH] KWSys: Add symlinks to directories as files (#12284) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This behaviour was previously broken; regardless of the RecurseThroughSymLinks value, symlinks to directories were NEVER added as files in the results. When RecurseThroughSymLinks is ON, symlinks to directories should be recursed as if they were the actual directories to gather the files within. However, when RecurseThroughSymLinks is OFF, symlinks to directories should be returned as files in the result. Inspired-by: Johan Björk <phb@spotify.com> --- Source/kwsys/Glob.cxx | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Source/kwsys/Glob.cxx b/Source/kwsys/Glob.cxx index b33b926817..513eb64086 100644 --- a/Source/kwsys/Glob.cxx +++ b/Source/kwsys/Glob.cxx @@ -259,26 +259,23 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, } bool isDir = kwsys::SystemTools::FileIsDirectory(realname.c_str()); + bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname.c_str()); - if ( !isDir ) + if ( isDir && (!isSymLink || this->RecurseThroughSymlinks) ) { - if ( (this->Internals->Expressions.size() > 0) && - this->Internals->Expressions[ - this->Internals->Expressions.size()-1].find(fname.c_str()) ) + if (isSymLink) { - this->AddFile(this->Internals->Files, realname.c_str()); + ++this->FollowedSymlinkCount; } + this->RecurseDirectory(start+1, realname); } else { - bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname.c_str()); - if (!isSymLink || this->RecurseThroughSymlinks) + if ( (this->Internals->Expressions.size() > 0) && + this->Internals->Expressions[ + this->Internals->Expressions.size()-1].find(fname.c_str()) ) { - if (isSymLink) - { - ++this->FollowedSymlinkCount; - } - this->RecurseDirectory(start+1, realname); + this->AddFile(this->Internals->Files, realname.c_str()); } } } -- GitLab