Updater: Fix existing directory update logic

This commit is contained in:
Vicki Pfau 2023-07-31 18:23:08 -07:00
parent ec52154112
commit 5534d23690
1 changed files with 11 additions and 11 deletions

View File

@ -93,20 +93,20 @@ bool extractArchive(struct VDir* archive, const char* root, bool prefix) {
case VFS_DIRECTORY: case VFS_DIRECTORY:
fprintf(logfile, "mkdir %s\n", fname); fprintf(logfile, "mkdir %s\n", fname);
if (mkdir(path, 0755) < 0) { if (mkdir(path, 0755) < 0) {
bool redo = false; bool redo = true;
if (errno == EEXIST) { struct stat st;
struct stat st; if (errno != EEXIST || stat(path, &st) < 0) {
if (stat(path, &st) >= 0 && !S_ISDIR(st.st_mode)) { redo = false;
} else if (!S_ISDIR(st.st_mode)) {
#ifdef _WIN32 #ifdef _WIN32
wchar_t wpath[MAX_PATH + 1]; wchar_t wpath[MAX_PATH + 1];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH); MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH);
DeleteFileW(wpath); DeleteFileW(wpath);
#else #else
unlink(path); unlink(path);
#endif #endif
if (mkdir(path, 0755) >= 0) { if (mkdir(path, 0755) < 0) {
redo = true; redo = false;
}
} }
} }
if (!redo) { if (!redo) {