From 94030131de8053718db1dcc6b67a8df14220562f Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 27 Sep 2024 15:27:25 -0400 Subject: [PATCH] filesystem: Windows SDL_SYS_CreateDirectory should succeed if dir exists. --- src/filesystem/windows/SDL_sysfsops.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/filesystem/windows/SDL_sysfsops.c b/src/filesystem/windows/SDL_sysfsops.c index f3210648d9..da700d5247 100644 --- a/src/filesystem/windows/SDL_sysfsops.c +++ b/src/filesystem/windows/SDL_sysfsops.c @@ -167,7 +167,16 @@ bool SDL_SYS_CreateDirectory(const char *path) return false; } - const DWORD rc = CreateDirectoryW(wpath, NULL); + DWORD rc = CreateDirectoryW(wpath, NULL); + if (!rc && (GetLastError() == ERROR_ALREADY_EXISTS)) { + WIN32_FILE_ATTRIBUTE_DATA winstat; + if (GetFileAttributesExW(wpath, GetFileExInfoStandard, &winstat)) { + if (winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + rc = 1; // exists and is already a directory: cool. + } + } + } + SDL_free(wpath); if (!rc) { return WIN_SetError("Couldn't create directory");