Commit dc42b3c4 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Backport MDEV-17504 to 5.5


mysql_install_db.exe should not remove datadir, if it was not created by
it.
parent 2450fd67
...@@ -351,7 +351,7 @@ IF(WIN32) ...@@ -351,7 +351,7 @@ IF(WIN32)
${CMAKE_CURRENT_BINARY_DIR}/mysql_bootstrap_sql.c ${CMAKE_CURRENT_BINARY_DIR}/mysql_bootstrap_sql.c
COMPONENT Server COMPONENT Server
) )
TARGET_LINK_LIBRARIES(mysql_install_db mysys) TARGET_LINK_LIBRARIES(mysql_install_db mysys shlwapi)
ADD_LIBRARY(winservice STATIC winservice.c) ADD_LIBRARY(winservice STATIC winservice.c)
TARGET_LINK_LIBRARIES(winservice shell32) TARGET_LINK_LIBRARIES(winservice shell32)
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <shellapi.h> #include <shellapi.h>
#include <accctrl.h> #include <accctrl.h>
#include <aclapi.h> #include <aclapi.h>
struct IUnknown;
#include <shlwapi.h>
#define USAGETEXT \ #define USAGETEXT \
"mysql_install_db.exe Ver 1.00 for Windows\n" \ "mysql_install_db.exe Ver 1.00 for Windows\n" \
...@@ -532,20 +534,78 @@ static int create_db_instance() ...@@ -532,20 +534,78 @@ static int create_db_instance()
DWORD cwd_len= MAX_PATH; DWORD cwd_len= MAX_PATH;
char cmdline[3*MAX_PATH]; char cmdline[3*MAX_PATH];
FILE *in; FILE *in;
bool cleanup_datadir= true;
DWORD last_error;
verbose("Running bootstrap"); verbose("Running bootstrap");
GetCurrentDirectory(cwd_len, cwd); GetCurrentDirectory(cwd_len, cwd);
CreateDirectory(opt_datadir, NULL); /*ignore error, it might already exist */
/* Create datadir and datadir/mysql, if they do not already exist. */
if (!CreateDirectory(opt_datadir, NULL) && (GetLastError() != ERROR_ALREADY_EXISTS))
{
last_error = GetLastError();
switch(last_error)
{
case ERROR_ACCESS_DENIED:
die("Can't create data directory '%s' (access denied)\n",
opt_datadir);
break;
case ERROR_PATH_NOT_FOUND:
die("Can't create data directory '%s' "
"(one or more intermediate directories do not exist)\n",
opt_datadir);
break;
default:
die("Can't create data directory '%s', last error %u\n",
opt_datadir, last_error);
break;
}
}
if (!SetCurrentDirectory(opt_datadir)) if (!SetCurrentDirectory(opt_datadir))
{ {
die("Cannot set current directory to '%s'\n",opt_datadir); last_error = GetLastError();
return -1; switch (last_error)
{
case ERROR_DIRECTORY:
die("Can't set current directory to '%s', the path is not a valid directory \n",
opt_datadir);
break;
default:
die("Can' set current directory to '%s', last error %u\n",
opt_datadir, last_error);
break;
}
}
if (PathIsDirectoryEmpty(opt_datadir))
{
cleanup_datadir= false;
} }
CreateDirectory("mysql",NULL); if (!CreateDirectory("mysql",NULL))
CreateDirectory("test", NULL); {
last_error = GetLastError();
DWORD attributes;
switch(last_error)
{
case ERROR_ACCESS_DENIED:
die("Can't create subdirectory 'mysql' in '%s' (access denied)\n",opt_datadir);
break;
case ERROR_ALREADY_EXISTS:
attributes = GetFileAttributes("mysql");
if (attributes == INVALID_FILE_ATTRIBUTES)
die("GetFileAttributes() failed for existing file '%s\\mysql', last error %u",
opt_datadir, GetLastError());
else if (!(attributes & FILE_ATTRIBUTE_DIRECTORY))
die("File '%s\\mysql' exists, but it is not a directory", opt_datadir);
break;
}
}
/* /*
Set data directory permissions for both current user and Set data directory permissions for both current user and
...@@ -642,7 +702,7 @@ static int create_db_instance() ...@@ -642,7 +702,7 @@ static int create_db_instance()
} }
end: end:
if (ret) if (ret && cleanup_datadir)
{ {
SetCurrentDirectory(cwd); SetCurrentDirectory(cwd);
clean_directory(opt_datadir); clean_directory(opt_datadir);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment