Wonky rename semantics on Windows

Started by Thomas Munroabout 7 years ago2 messages
#1Thomas Munro
thomas.munro@enterprisedb.com

Hi,

I saw this failure:

https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=bowerbird&dt=2018-11-21%2000%3A51%3A32

I think there may be more than one thing going wrong there, but one
things I noticed was this:

2018-11-20 21:49:50.935 EST [9700:18] LOG: could not rename temporary
statistics file "pg_stat_tmp/global.tmp" to "pg_stat_tmp/global.stat":
Permission denied

That probably has to do with rename() not behaving like Unix, and I
see there have been threads about this before[1]/messages/by-id/CAPpHfds9trA6ipezK3BsuuOSQwEmESiqj8pkOxACFJpoLpcoNw@mail.gmail.com.

Googling led me to some recently posted clues on SO and elsewhere
about a flag FILE_RENAME_FLAG_POSIX_SEMANTICS which can be used with
SetFileInformationByHandle(), that wasn't mentioned in the earlier
-hackers threads. I tried it on AppVeyor. It appears to work, even
when both source and target file name exist and both files currently
have an open handle. Perhaps they needed this for the Windows 10 WSL
stuff?

https://github.com/macdice/hello-windows/blob/rename-test/test.c
https://ci.appveyor.com/project/macdice/hello-windows/builds/20450990

I wonder if they also have a new secret fully POSIX unlink() hidden in
there somewhere too.

[1]: /messages/by-id/CAPpHfds9trA6ipezK3BsuuOSQwEmESiqj8pkOxACFJpoLpcoNw@mail.gmail.com

--
Thomas Munro
http://www.enterprisedb.com

#2Thomas Munro
thomas.munro@enterprisedb.com
In reply to: Thomas Munro (#1)
Re: Wonky rename semantics on Windows

On Wed, Nov 21, 2018 at 5:43 PM Thomas Munro
<thomas.munro@enterprisedb.com> wrote:

Googling led me to some recently posted clues on SO and elsewhere
about a flag FILE_RENAME_FLAG_POSIX_SEMANTICS which can be used with
SetFileInformationByHandle(), that wasn't mentioned in the earlier
-hackers threads. I tried it on AppVeyor. It appears to work, even
when both source and target file name exist and both files currently
have an open handle. Perhaps they needed this for the Windows 10 WSL
stuff?

Erm, looks like I posted too soon. My 5 minute hack didn't check the
return code correctly (it's zero for failure). Oh well. I don't
actually plan to investigate this any further myself, being
non-Windows-enabled, but it looks like there might still be something
promising here.

--
Thomas Munro
http://www.enterprisedb.com