Make g_rename() replace existing files on Win32?
- From: Tor Lillqvist <tml iki fi>
- To: gtk-devel-list gnome org
- Subject: Make g_rename() replace existing files on Win32?
- Date: Wed, 30 Nov 2005 02:54:22 +0200
The rename() function in the Microsoft C library calls the Win32 API
MoveFile(), which does not replace existing files.
I now notice there is also a function MoveFileEx(), to which one can
specify the flag MOVEFILE_REPLACE_EXISTING, which enables atomic
replacement of an existing file. Sigh, why didn't I notice that
earlier...
What do you think, should g_rename() be changed to use MoveFileEx()
instead of rename() on NT-based Windowses? My vote is yes.
(Well, MoveFileExW() instead of _wrename(). On NT-based Windows
gstdio.c uses the wide-char API.)
This is, strictly speaking, an API change. If there is code out there
that has relied on g_rename() failing if the target file exists, such
code would break after the change.
But how likely is it that there is such code out there? Presumably,
much more common is that code ported from Unix has added conditional
code for Win32 that first removes the file. (Thus introducing the
possibility of various glitches as there is a short time interval
during which the target file does not exist.) Such code would continue
to work as before. And once the change is available in a released GLib
version, the remove can be dropped, or made conditional upon GLib
version using glib_check_version().
Note that it still isn't possible to rename (or remove) open files,
this doesn't affect that.
--tml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]