Fix error handling in temp-file deletion with log_temp_files active.
Fix error handling in temp-file deletion with log_temp_files active.

The original coding in FileClose() reset the file-is-temp flag before
unlinking the file, so that if control came back through due to an error,
it wouldn't try to unlink the file twice.  This was correct when written,
but when the log_temp_files feature was added, the logging action was put
in between those two steps.  An error occurring during the logging action
--- such as a query cancel --- would result in the unlink not getting done
at all, as in recent report from Michael Glaesemann.

To fix this, make sure that we do both the stat and the unlink before doing
anything that could conceivably CHECK_FOR_INTERRUPTS.  There is a judgment
call here, which is which log message to emit first: if you can see only
one, which should it be?  I chose to log unlink failure at the risk of
losing the log_temp_files log message --- after all, if the unlink does
fail, the temp file is still there for you to see.

Back-patch to all versions that have log_temp_files.  The code was OK
before that.

yazun/postgres-xl,zeroae/postgres-xl,lisakowen/gpdb,arcivanov/postgres-xl,Postgres-XL/Postgres-XL,greenplum-db/gpdb,ashwinstar/gpdb,tpostgres-projects/tPostgres,arcivanov/postgres-xl,greenplum-db/gpdb,techdragon/Postgres-XL,ashwinstar/gpdb,techdragon/Postgres-XL,ashwinstar/gpdb,techdragon/Postgres-XL,50wu/gpdb,ovr/postgres-xl,ashwinstar/gpdb,Postgres-XL/Postgres-XL,jmcatamney/gpdb,xinzweb/gpdb,adam8157/gpdb,ovr/postgres-xl,postmind-net/postgres-xl,postmind-net/postgres-xl,jmcatamney/gpdb,oberstet/postgres-xl,greenplum-db/gpdb,kmjungersen/PostgresXL,pavanvd/postgres-xl,kmjungersen/PostgresXL,adam8157/gpdb,zeroae/postgres-xl,50wu/gpdb,lisakowen/gpdb,yazun/postgres-xl,ashwinstar/gpdb,arcivanov/postgres-xl,pavanvd/postgres-xl,xinzweb/gpdb,arcivanov/postgres-xl,jmcatamney/gpdb,oberstet/postgres-xl,Postgres-XL/Postgres-XL,adam8157/gpdb,tpostgres-projects/tPostgres,tpostgres-projects/tPostgres,zeroae/postgres-xl,Postgres-XL/Postgres-XL,zeroae/postgres-xl,jmcatamney/gpdb,tpostgres-projects/tPostgres,adam8157/gpdb,50wu/gpdb,lisakowen/gpdb,postmind-net/postgres-xl,snaga/postgres-xl,oberstet/postgres-xl,yazun/postgres-xl,jmcatamney/gpdb,ovr/postgres-xl,adam8157/gpdb,ovr/postgres-xl,xinzweb/gpdb,snaga/postgres-xl,yazun/postgres-xl,snaga/postgres-xl,ashwinstar/gpdb,oberstet/postgres-xl,lisakowen/gpdb,zeroae/postgres-xl,Postgres-XL/Postgres-XL,xinzweb/gpdb,pavanvd/postgres-xl,50wu/gpdb,postmind-net/postgres-xl,lisakowen/gpdb,ovr/postgres-xl,oberstet/postgres-xl,snaga/postgres-xl,xinzweb/gpdb,jmcatamney/gpdb,50wu/gpdb,50wu/gpdb,adam8157/gpdb,pavanvd/postgres-xl,greenplum-db/gpdb,yazun/postgres-xl,50wu/gpdb,xinzweb/gpdb,lisakowen/gpdb,greenplum-db/gpdb,techdragon/Postgres-XL,techdragon/Postgres-XL,ashwinstar/gpdb,xinzweb/gpdb,adam8157/gpdb,greenplum-db/gpdb,kmjungersen/PostgresXL,greenplum-db/gpdb,tpostgres-projects/tPostgres,postmind-net/postgres-xl,lisakowen/gpdb,greenplum-db/gpdb,lisakowen/gpdb,jmcatamney/gpdb,arcivanov/postgres-xl,pavanvd/postgres-xl,adam8157/gpdb,jmcatamney/gpdb,50wu/gpdb,kmjungersen/PostgresXL,xinzweb/gpdb,snaga/postgres-xl,arcivanov/postgres-xl,kmjungersen/PostgresXL,ashwinstar/gpdb