* [AssetBrowser] BugFix: Address an error where deleting directories may result in an infinite loop.

This commit is contained in:
Robert MacGregor 2021-10-25 16:14:11 -04:00
parent 14ebeaf3eb
commit 4082fd36e3

View file

@ -277,9 +277,11 @@ function directoryHandler::deleteFolder(%this, %folderPath)
%fullPath = makeFullPath(%folderPath); %fullPath = makeFullPath(%folderPath);
//First, wipe out any files inside the folder first //First, wipe out any files inside the folder first
%file = findFirstFileMultiExpr( %fullPath @ "/*.*", true); %file = findFirstFileMultiExpr( %fullPath @ "/*", true);
while( %file !$= "" ) while( %file !$= "" )
{
if (isFile(%file))
{ {
%success = fileDelete( %file ); %success = fileDelete( %file );
@ -288,16 +290,33 @@ function directoryHandler::deleteFolder(%this, %folderPath)
error("doDeleteFolder - unable to delete file " @ %file); error("doDeleteFolder - unable to delete file " @ %file);
return; return;
} }
}
%file = findNextFileMultiExpr( %fullPath @ "/*.*" ); %file = findNextFileMultiExpr( %fullPath @ "/*" );
} }
//next, walk through and delete any subfolders that may be remaining //next, walk through and delete any subfolders that may be remaining
%finalDeleteAttempt = false;
while(IsDirectory(%fullPath) && fileDelete(%fullPath) == 0) while(IsDirectory(%fullPath) && fileDelete(%fullPath) == 0)
{ {
//We couldn't delete the folder, so get a directory list and recurse through it, deleteing them as we go //We couldn't delete the folder, so get a directory list and recurse through it, deleteing them as we go
%paths = getDirectoryList(%fullPath); %paths = getDirectoryList(%fullPath);
for(%i=0; %i < getFieldCount(%paths); %i++)
// If nothing is in this directory, let the loop run once more and if that fails we're not going
// to delete the folder. This prevents an infinite loop if for some reason the directory cannot
// be deleted.
%pathCount = getFieldCount(%paths);
if (%pathCount == 0)
{
if (%finalDeleteattempt)
{
error("doDeleteFolder - unable to delete directory " @ %fullPath);
return;
}
%finalDeleteAttempt = true;
continue;
}
for(%i=0; %i < %pathCount; %i++)
{ {
%childPath = getField(%paths, %i); %childPath = getField(%paths, %i);
%this.deleteFolder(%fullPath @ "/" @ %childPath); %this.deleteFolder(%fullPath @ "/" @ %childPath);