Add some delay and a maximum attempt number in GenerateTempDir to avoid getting oversized execution log files

This commit is contained in:
Pierre Muller 2021-11-12 12:08:20 +01:00
parent 550d0481b3
commit 52cc8df079

View File

@ -30,14 +30,19 @@ var
TmpFileList : TStringList; TmpFileList : TStringList;
function GenerateTempDir: string; function GenerateTempDir: string;
const
max_attempts = 10;
var var
TempDirName: string; TempDirName: string;
BaseTempDir: string; BaseTempDir: string;
Done: Boolean = False; Done: Boolean = False;
attempt: longint;
begin begin
BaseTempDir := GetTempDir(False); BaseTempDir := GetTempDir(False);
Result := no_temp_dir_generated; Result := no_temp_dir_generated;
attempt := 0;
repeat repeat
inc(attempt);
try try
TempDirName := BaseTempDir + 'dosboxwrappertmp_' + IntToStr(Random(100000)); TempDirName := BaseTempDir + 'dosboxwrappertmp_' + IntToStr(Random(100000));
if verbose then if verbose then
@ -56,8 +61,13 @@ begin
raise; raise;
end; end;
end; end;
on E: Exception do
begin
Writeln('Exception ',E.Message);
Sleep(1000);
end; end;
until Done; end;
until Done or (attempt > max_attempts);
Result := TempDirName + DirectorySeparator; Result := TempDirName + DirectorySeparator;
end; end;