mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Merge pull request #635 from Ragora/bugfix-asset-browser-delete-directory-loop
BugFix: Address an error where deleting directories may result in an infinite loop
This commit is contained in:
commit
7f5766a7fc
1 changed files with 28 additions and 9 deletions
|
|
@ -277,27 +277,46 @@ 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 !$= "" )
|
||||||
{
|
{
|
||||||
%success = fileDelete( %file );
|
if (isFile(%file))
|
||||||
|
|
||||||
if(!%success)
|
|
||||||
{
|
{
|
||||||
error("doDeleteFolder - unable to delete file " @ %file);
|
%success = fileDelete( %file );
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
%file = findNextFileMultiExpr( %fullPath @ "/*.*" );
|
if(!%success)
|
||||||
|
{
|
||||||
|
error("doDeleteFolder - unable to delete file " @ %file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue