From 4082fd36e39276fb6fbedf212b974c8272fc69ef Mon Sep 17 00:00:00 2001 From: Robert MacGregor Date: Mon, 25 Oct 2021 16:14:11 -0400 Subject: [PATCH] * [AssetBrowser] BugFix: Address an error where deleting directories may result in an infinite loop. --- .../scripts/directoryHandling.tscript | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript index 4f13dfb8b..329e2763f 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript @@ -277,27 +277,46 @@ function directoryHandler::deleteFolder(%this, %folderPath) %fullPath = makeFullPath(%folderPath); //First, wipe out any files inside the folder first - %file = findFirstFileMultiExpr( %fullPath @ "/*.*", true); + %file = findFirstFileMultiExpr( %fullPath @ "/*", true); while( %file !$= "" ) { - %success = fileDelete( %file ); - - if(!%success) + if (isFile(%file)) { - error("doDeleteFolder - unable to delete file " @ %file); - return; - } + %success = fileDelete( %file ); - %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 + %finalDeleteAttempt = false; 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 %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); %this.deleteFolder(%fullPath @ "/" @ %childPath);