X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/988f7eec77d3a6cbc08980252a0349b3c6be7bf4..17beda75ef9780ebef5044e41889a9b598dcf186:/src/common/filename.cpp diff --git a/src/common/filename.cpp b/src/common/filename.cpp index b52e989acd..6ffcbf1288 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -99,7 +99,9 @@ #endif #ifdef __WINDOWS__ -#include "wx/msw/private.h" + #include "wx/msw/private.h" + #include // for CLSID_ShellLink + #include "wx/msw/missing.h" #endif #if defined(__WXMAC__) @@ -737,7 +739,12 @@ wxFileSystemObjectExists(const wxString& path, int flags) if ( S_ISDIR(st.st_mode) ) return acceptDir; if ( S_ISLNK(st.st_mode) ) - return (flags & wxFILE_EXISTS_SYMLINK) != 0; + { + // Take care to not test for "!= 0" here as this would erroneously + // return true if only wxFILE_EXISTS_NO_FOLLOW, which is part of + // wxFILE_EXISTS_SYMLINK, is set too. + return (flags & wxFILE_EXISTS_SYMLINK) == wxFILE_EXISTS_SYMLINK; + } if ( S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) ) return (flags & wxFILE_EXISTS_DEVICE) != 0; if ( S_ISFIFO(st.st_mode) ) @@ -1415,6 +1422,20 @@ bool wxFileName::Rmdir(const wxString& dir, int flags) if ( flags != 0 ) // wxPATH_RMDIR_FULL or wxPATH_RMDIR_RECURSIVE #endif // !__WINDOWS__ { +#ifndef __WINDOWS__ + if ( flags & wxPATH_RMDIR_RECURSIVE ) + { + // When deleting the tree recursively, we are supposed to delete + // this directory itself even when it is a symlink -- but without + // following it. Do it here as wxRmdir() would simply follow if + // called for a symlink. + if ( wxFileName::Exists(dir, wxFILE_EXISTS_SYMLINK) ) + { + return wxRemoveFile(dir); + } + } +#endif // !__WINDOWS__ + wxString path(dir); if ( path.Last() != wxFILE_SEP_PATH ) path += wxFILE_SEP_PATH; @@ -1426,8 +1447,11 @@ bool wxFileName::Rmdir(const wxString& dir, int flags) wxString filename; - // first delete all subdirectories - bool cont = d.GetFirst(&filename, "", wxDIR_DIRS | wxDIR_HIDDEN); + // First delete all subdirectories: notice that we don't follow + // symbolic links, potentially leading outside this directory, to avoid + // unpleasant surprises. + bool cont = d.GetFirst(&filename, wxString(), + wxDIR_DIRS | wxDIR_HIDDEN | wxDIR_NO_FOLLOW); while ( cont ) { wxFileName::Rmdir(path + filename, flags); @@ -1437,8 +1461,11 @@ bool wxFileName::Rmdir(const wxString& dir, int flags) #ifndef __WINDOWS__ if ( flags & wxPATH_RMDIR_RECURSIVE ) { - // delete all files too - cont = d.GetFirst(&filename, "", wxDIR_FILES | wxDIR_HIDDEN); + // Delete all files too and, for the same reasons as above, don't + // follow symlinks which could refer to the files outside of this + // directory and just delete the symlinks themselves. + cont = d.GetFirst(&filename, wxString(), + wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW); while ( cont ) { ::wxRemoveFile(path + filename); @@ -1677,13 +1704,6 @@ bool wxFileName::ReplaceHomeDir(wxPathFormat format) // quotation marks." #if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE -// The following lines are necessary under WinCE -// #include "wx/msw/private.h" -// #include -#include -#if defined(__WXWINCE__) -#include -#endif bool wxFileName::GetShortcutTarget(const wxString& shortcutPath, wxString& targetFilename,