From 4c839605b93729babc9577266aa56fa60bc353cd Mon Sep 17 00:00:00 2001 From: Josh Davies Date: Thu, 23 May 2024 13:31:42 +0100 Subject: [PATCH] Try to create the sort file at startup. If a bad path for FORMTMPSORT is specified, FORM doesn't notice until it tries to create a sort file and can't. In principle one can create a script which takes a long time to reach this point. Try to create the file immediately at startup, and Terminate if this fails. --- check/features.frm | 10 ++++++++++ sources/startup.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/check/features.frm b/check/features.frm index 351963a5..05665e7a 100644 --- a/check/features.frm +++ b/check/features.frm @@ -1135,3 +1135,13 @@ Print +s; assert succeeded? assert result("F") =~ expr("0"); *--#] Sortrealloc_2 : +*--#[ TempSortDir : +#: TempSortDir bad/path +Local test = 1; +.end +if mpi? + assert runtime_error?("Could not create sort file: bad/path/0formxxx.sor") +else + assert runtime_error?("Could not create sort file: bad/path/xformxxx.sor") +end +*--#] TempSortDir : diff --git a/sources/startup.c b/sources/startup.c index 4d7b930e..8aafdf03 100644 --- a/sources/startup.c +++ b/sources/startup.c @@ -801,6 +801,17 @@ classic:; while ( *t ) { *s++ = *t++; i++; } s[-2] = 'o'; *s = 0; } +/* + Try to create the sort file already, so we can Terminate earlier if this fails. +*/ + if ( ( AM.S0->file.handle = CreateFile((char *)AM.S0->file.name) ) < 0 ) { + MesPrint("Could not create sort file: %s", AM.S0->file.name); + Terminate(-1); + }; + /* Close and clean up the test file */ + CloseFile(AM.S0->file.handle); + AM.S0->file.handle = -1; + remove(AM.S0->file.name); /* With the stage4 and scratch file names we have to be a bit more careful. They are to be allocated after the threads are initialized when there