zig icon indicating copy to clipboard operation
zig copied to clipboard

std.windows: use atomic rename, if possible

Open matu3ba opened this issue 2 years ago • 1 comments
trafficstars

Mitigates #14978.

matu3ba avatar May 19 '23 19:05 matu3ba

As far as I understand, there are no tests currently. If wanted, I can add some to show that the posix behavior is what it claims.

matu3ba avatar May 19 '23 19:05 matu3ba

Closing abandoned pull request. Please open a new one if you wish to continue this work.

andrewrk avatar Jul 24 '23 21:07 andrewrk

Found it in mingw64 upstream via rg '.*FILE_RENAME.*': mingw-w64-headers/include/winbase.h:3122

#if _WIN32_WINNT >= _WIN32_WINNT_WIN10_RS1
#define FILE_RENAME_FLAG_REPLACE_IF_EXISTS 0x00000001
#define FILE_RENAME_FLAG_POSIX_SEMANTICS 0x00000002
#endif

#if _WIN32_WINNT >= _WIN32_WINNT_WIN10_RS3
#define FILE_RENAME_FLAG_SUPPRESS_PIN_STATE_INHERITANCE 0x00000004
#endif

  typedef struct _FILE_RENAME_INFO {
#if _WIN32_WINNT >= _WIN32_WINNT_WIN10_RS1
    __C89_NAMELESS union {
        BOOLEAN ReplaceIfExists;
        DWORD Flags;
    };
#else
    BOOLEAN ReplaceIfExists;
#endif
    HANDLE RootDirectory;
    DWORD FileNameLength;
    WCHAR FileName[1];
  } FILE_RENAME_INFO,*PFILE_RENAME_INFO;

I'll probably make a PR next weekend unless somebody else is faster.

matu3ba avatar Aug 06 '23 18:08 matu3ba