On Windows, when a file is deleted and another process still has an open file handle on it, the file goes into "pending deletion" state where it still shows up in directory listing, but isn't accessible otherwise. That confuses RemoveOldXLogFiles(), making it think that the file hasn't been archived yet, while it actually was, and it was deleted along with the .done file.
On Windows, when a file is deleted and another process still has an open
file handle on it, the file goes into "pending deletion" state where it
still shows up in directory listing, but isn't accessible otherwise. That
confuses RemoveOldXLogFiles(), making it think that the file hasn't been
archived yet, while it actually was, and it was deleted along with the .done
file.

Fix that by renaming the file with ".deleted" extension before deleting it.
Also check the return value of rename() and unlink(), so that if the removal
fails for any reason (e.g another process is holding the file locked), we
don't delete the .done file until the WAL file is really gone.

Backpatch to 8.2, which is the oldest version supported on Windows.

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