]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxDIR_NO_FOLLOW flag for wxDir iteration.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 23 Oct 2012 23:57:32 +0000 (23:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 23 Oct 2012 23:57:32 +0000 (23:57 +0000)
This flag allows to avoid following the symbolic links during the directory
traversal. In particular, this means that links to the directories
(potentially outside the directory being traversed) are not considered as
directories at all when it is used, potentially avoiding surprises.

Closes #14542.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72740 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/dir.h
interface/wx/dir.h
src/unix/dir.cpp

index 7e772e11cbbd08c2873d3ca46182fce39bbba36b..0611debd8fc22fc6f598d892adaa7f75c74a5eb0 100644 (file)
@@ -531,6 +531,7 @@ All:
 
 - Add wxEvtHandler::CallAfter() method for asynchronous method calls.
 - Add support for symlinks to wxFileName (David Hart).
+- Add wxDIR_NO_FOLLOW flag for wxDir traversal (David Hart).
 - Allow testing for symlink/FIFO/socket existence in wxFileName (David Hart).
 - Many important bug fixes in wxFileSystemWatcher (David Hart).
 - Add separate read/written bytes counters and per-direction NOWAIT and WAITALL
index 83dab66454b83c7a296bdcc1b237d76c1b893e8b..de389aef892e76b3e96d33e3904a0c1f1e64b66c 100644 (file)
@@ -22,14 +22,17 @@ class WXDLLIMPEXP_FWD_BASE wxArrayString;
 // constants
 // ----------------------------------------------------------------------------
 
-// these flags define what kind of filenames is included in the list of files
-// enumerated by GetFirst/GetNext
+// These flags affect the behaviour of GetFirst/GetNext() and Traverse().
+// They define what types are included in the list of items they produce.
+// Note that wxDIR_NO_FOLLOW is relevant only on Unix and ignored under systems
+// not supporting symbolic links.
 enum wxDirFlags
 {
     wxDIR_FILES     = 0x0001,       // include files
     wxDIR_DIRS      = 0x0002,       // include directories
     wxDIR_HIDDEN    = 0x0004,       // include hidden files
     wxDIR_DOTDOT    = 0x0008,       // include '.' and '..'
+    wxDIR_NO_FOLLOW = 0x0010,       // don't dereference any symlink
 
     // by default, enumerate everything except '.' and '..'
     wxDIR_DEFAULT   = wxDIR_FILES | wxDIR_DIRS | wxDIR_HIDDEN
index f4b25eb29f2a62f841216dedb02480599ea0f87e..14f0148e0e0acc67429b7cc28f3b7675ec9b9c83 100644 (file)
@@ -94,8 +94,8 @@ public:
 
 
 /**
-    These flags define what kind of filenames are included in the list of files
-    enumerated by wxDir::GetFirst() and wxDir::GetNext().
+    These flags affect the behaviour of GetFirst/GetNext() and Traverse(),
+    determining what types are included in the list of items they produce.
 */
 enum wxDirFlags
 {
@@ -104,8 +104,28 @@ enum wxDirFlags
     wxDIR_HIDDEN    = 0x0004,   ///< Includes hidden files.
     wxDIR_DOTDOT    = 0x0008,   ///< Includes "." and "..".
 
-    //! Combination of the @c wxDIR_FILES, @c wxDIR_DIRS, @c wxDIR_HIDDEN flags
-    //! defined above.
+    /**
+        Don't follow symbolic links during the directory traversal.
+
+        This flag is ignored under systems not supporting symbolic links (i.e.
+        non-Unix ones).
+
+        Notice that this flag is @e not included in wxDIR_DEFAULT and so the
+        default behaviour of wxDir::Traverse() is to follow symbolic links,
+        even if they lead outside of the directory being traversed.
+
+        @since 2.9.5
+     */
+    wxDIR_NO_FOLLOW = 0x0010,
+
+    /**
+        Default directory traversal flags include both files and directories,
+        even hidden.
+
+        Notice that by default wxDIR_NO_FOLLOW is @e not included, meaning that
+        symbolic links are followed by default. If this is not desired, you
+        must pass that flag explicitly.
+     */
     wxDIR_DEFAULT   = wxDIR_FILES | wxDIR_DIRS | wxDIR_HIDDEN
 };
 
index f0e6cd919754f7d91f1d28b52eb5820841fa04d3..2924741545652a961e616360d0e390e274d97735 100644 (file)
@@ -150,10 +150,13 @@ bool wxDirData::Read(wxString *filename)
             break;
         }
 
-        // check the type now: notice that we want to check the type of this
-        // path itself and not whatever it points to in case of a symlink
+        // check the type now: notice that we may want to check the type of
+        // the path itself and not whatever it points to in case of a symlink
         wxFileName fn = wxFileName::DirName(path + de_d_name);
-        fn.DontFollowLink();
+        if ( m_flags & wxDIR_NO_FOLLOW )
+        {
+            fn.DontFollowLink();
+        }
 
         if ( !(m_flags & wxDIR_FILES) && !fn.DirExists() )
         {