g_rename (on Windows) will only work for closed files
Submitted by John Emmas
Link to original bug (#674214)
Description
Created attachment 212164 3 x functions to modify the behaviour of g_rename() (Windows only)
I'm using glib-win32, version 2.24. In that version, the functions g_open(), g_creat() and g_fopen() defer to _wopen(), _wcreat() and _wfopen() respectively. This is very similar to the corresponding arrangement for Linux. Unfortunately however, those Windows functions do not support renaming a file whilst it's open. As a result, g_rename() behaves differently on the Windows platform compared to its Linux behaviour, where files can be renamed - even while there are file handles still open.
To get around this restriction I've re-written those 3 functions to use CreateFile() on the Windows platform. I've managed to keep the API exactly the same as it was previously - but the flags and attributes expected by CreateFile() are totally different from _wopen() etc. So I've needed to convert the incoming flags and attributes to their appropriate counterparts (which makes the code look very longwinded).
I've been using the modified code for several weeks and am very pleased with the result. However, it would benefit from someone else reviewing my changes. Two pairs of eyes are always better than one! I'd like to offer my revisions to be considered for adoption. Please note that there was no need to modify g_rename() itself.
I've attached a small 'C' file which includes the new versions of those 3 functions in their entirety. If accepted, they'd need to replace the functions already in gstdio.c With thanks.
John Emmas
Attachment 212164, "3 x functions to modify the behaviour of g_rename() (Windows only)":
modified_functions_to_support_enhanced_windows__g_rename.c
Version: 2.24.x