Skip to content

Commit

Permalink
Don't follow symlinks in RecursivelyEnumerate
Browse files Browse the repository at this point in the history
Projects will only have symlinks in them if they have been tampered with, and then
following the links, especially when doing CleanDir(), would be dangerous.  So don't.

Improved comments, otherwise it isn't clear that CleanDir is needed on Windows
and Linux, not just Mac.  It is deleting whole subdirs, not just .DS_Store files.
  • Loading branch information
JamesCrook committed Feb 20, 2017
1 parent 085c260 commit 0a518b6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/DirManager.cpp
Expand Up @@ -147,6 +147,9 @@ wxMemorySize GetFreeMemory()
// subdirs of subdirs. Files in the passed-in directory will not be
// enumerated. Also, the passed-in directory is the last entry added
// to the list.
// JKC: Using flag wxDIR_NO_FOLLOW to NOT follow symbolic links.
// Directories and files inside a project should never be symbolic
// links, so if we find one, do not follow it.
static int RecursivelyEnumerate(wxString dirPath,
wxArrayString& filePathArray, // output: all files in dirPath tree
wxString dirspec,
Expand All @@ -163,7 +166,7 @@ static int RecursivelyEnumerate(wxString dirPath,
wxString name;

if (bFiles){
cont= dir.GetFirst(&name, dirspec, wxDIR_FILES | wxDIR_HIDDEN);
cont= dir.GetFirst(&name, dirspec, wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
while ( cont ){
wxString filepath = dirPath + wxFILE_SEP_PATH + name;

Expand All @@ -178,7 +181,7 @@ static int RecursivelyEnumerate(wxString dirPath,
}
}

cont= dir.GetFirst(&name, dirspec, wxDIR_DIRS);
cont= dir.GetFirst(&name, dirspec, wxDIR_DIRS | wxDIR_NO_FOLLOW);
while ( cont ){
wxString subdirPath = dirPath + wxFILE_SEP_PATH + name;
count += RecursivelyEnumerate(
Expand Down Expand Up @@ -412,12 +415,13 @@ void DirManager::CleanDir(

wxArrayString filePathArray, dirPathArray;

// Subtract 1 because we don't want to DELETE the global temp directory,
// which this will find and list last.
int countFiles =
RecursivelyEnumerate(path, filePathArray, dirSpec, true, false);
int countDirs =
RecursivelyEnumerate(path, dirPathArray, dirSpec, false, true);

// Subtract 1 because we don't want to DELETE the global temp directory,
// which this will find and list last.
if (!removeTop) {
// Remove the globaltemp itself from the array
--countDirs;
Expand Down Expand Up @@ -559,7 +563,7 @@ bool DirManager::SetProject(wxString& newProjPath, wxString& newProjName, const
// folders have been moved away already, but:
// to fix bug1567 on Mac, we need to find the extraneous .DS_Store files
// that we didn't put there, but that Finder may insert into the folders,
// and mercilessly remove them too.
// and mercilessly remove them, in addition to removing the directories.

CleanDir(
cleanupLoc1, wxEmptyString, _("Cleaning up cache directories"), true);
Expand Down

0 comments on commit 0a518b6

Please sign in to comment.