diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2019-01-11 01:44:07 +0100 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2019-01-11 01:45:09 +0100 |
commit | dc42b3c4d9546153e2f0049393e3771e21551679 (patch) | |
tree | 1231d23f45e253a49cd6fa21745c6ea40d82a56b /sql | |
parent | 2450fd67ed403bb8a154925dd1ca500b23f5b3cc (diff) | |
download | mariadb-git-dc42b3c4d9546153e2f0049393e3771e21551679.tar.gz |
Backport MDEV-17504 to 5.5
mysql_install_db.exe should not remove datadir, if it was not created by
it.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sql/mysql_install_db.cc | 72 |
2 files changed, 67 insertions, 7 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 02196a7e366..6648b7a2612 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -351,7 +351,7 @@ IF(WIN32) ${CMAKE_CURRENT_BINARY_DIR}/mysql_bootstrap_sql.c COMPONENT Server ) - TARGET_LINK_LIBRARIES(mysql_install_db mysys) + TARGET_LINK_LIBRARIES(mysql_install_db mysys shlwapi) ADD_LIBRARY(winservice STATIC winservice.c) TARGET_LINK_LIBRARIES(winservice shell32) diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index 9c1a234241f..9d2b261b46c 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -28,6 +28,8 @@ #include <shellapi.h> #include <accctrl.h> #include <aclapi.h> +struct IUnknown; +#include <shlwapi.h> #define USAGETEXT \ "mysql_install_db.exe Ver 1.00 for Windows\n" \ @@ -532,20 +534,78 @@ static int create_db_instance() DWORD cwd_len= MAX_PATH; char cmdline[3*MAX_PATH]; FILE *in; + bool cleanup_datadir= true; + DWORD last_error; verbose("Running bootstrap"); 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)) { - die("Cannot set current directory to '%s'\n",opt_datadir); - return -1; + last_error = GetLastError(); + 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); - CreateDirectory("test", NULL); + if (!CreateDirectory("mysql",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 @@ -642,7 +702,7 @@ static int create_db_instance() } end: - if (ret) + if (ret && cleanup_datadir) { SetCurrentDirectory(cwd); clean_directory(opt_datadir); |