mirror of https://github.com/mgba-emu/mgba.git
Updater: Fix overwriting files with directories
This commit is contained in:
parent
1e68020d1c
commit
c8cfaefcc8
|
@ -89,9 +89,27 @@ bool extractArchive(struct VDir* archive, const char* root, bool prefix) {
|
|||
switch (vde->type(vde)) {
|
||||
case VFS_DIRECTORY:
|
||||
fprintf(logfile, "mkdir %s\n", fname);
|
||||
if (mkdir(path, 0755) < 0 && errno != EEXIST) {
|
||||
fprintf(logfile, "error %i\n", errno);
|
||||
return false;
|
||||
if (mkdir(path, 0755) < 0) {
|
||||
bool redo = false;
|
||||
if (errno == EEXIST) {
|
||||
struct stat st;
|
||||
if (stat(path, &st) >= 0 && !S_ISDIR(st.st_mode)) {
|
||||
#ifdef _WIN32
|
||||
wchar_t wpath[MAX_PATH + 1];
|
||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH);
|
||||
DeleteFileW(wpath);
|
||||
#else
|
||||
unlink(path);
|
||||
#endif
|
||||
if (mkdir(path, 0755) >= 0) {
|
||||
redo = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!redo) {
|
||||
fprintf(logfile, "error %i\n", errno);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!prefix) {
|
||||
struct VDir* subdir = archive->openDir(archive, fname);
|
||||
|
|
Loading…
Reference in New Issue