Updater: Fix rewriting folders and files on Windows (fixes #3384)

This commit is contained in:
Vicki Pfau 2024-12-28 22:45:39 -08:00
parent d82fc3dec1
commit ad0d3972a6
2 changed files with 13 additions and 8 deletions

View File

@ -48,6 +48,7 @@ Misc:
- Qt: Show a dummy shader settings tab if shaders aren't supported - Qt: Show a dummy shader settings tab if shaders aren't supported
- Res: Port NSO-gba-colors shader (closes mgba.io/i/2834) - Res: Port NSO-gba-colors shader (closes mgba.io/i/2834)
- Scripting: Add `callbacks:oneshot` for single-call callbacks - Scripting: Add `callbacks:oneshot` for single-call callbacks
- Updater: Fix rewriting folders and files on Windows (fixes mgba.io/i/3384)
0.10.4: (2024-12-07) 0.10.4: (2024-12-07)
Emulation fixes: Emulation fixes:

View File

@ -133,14 +133,11 @@ bool extractArchive(struct VDir* archive, const char* root, bool prefix) {
errno = 0; errno = 0;
vfOut = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC); vfOut = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
if (!vfOut) { if (!vfOut) {
if (errno == EACCES) { int error = errno;
#ifdef _WIN32 struct stat st;
Sleep(1000); if (error == EISDIR || (stat(path, &st) >= 0 && S_ISDIR(st.st_mode))) {
#else // Windows maps STATUS_FILE_IS_A_DIRECTORY to ERROR_ACCESS_DENIED,
sleep(1); // which then gets mapped to EACCESS, because everything is awful
#endif
vfOut = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
} else if (errno == EISDIR) {
fprintf(logfile, "rm -r %s\n", path); fprintf(logfile, "rm -r %s\n", path);
if (!rmdirRecursive(VDirOpen(path))) { if (!rmdirRecursive(VDirOpen(path))) {
return false; return false;
@ -151,6 +148,13 @@ bool extractArchive(struct VDir* archive, const char* root, bool prefix) {
RemoveDirectoryW(wpath); RemoveDirectoryW(wpath);
#else #else
rmdir(path); rmdir(path);
#endif
vfOut = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
} else if (error == EACCES || error == ETXTBSY) {
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif #endif
vfOut = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC); vfOut = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
} }