diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2019-02-02 13:00:15 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2019-02-02 13:00:15 +0200 |
commit | 213ece2f2e8c23ee0e727cc02dcecfae6f510ca2 (patch) | |
tree | 5ce93ecb5caa9a58ebc08f8cd3e94c59d7219377 /sql/mysql_install_db.cc | |
parent | c1e1764fc4b913ee688b383aac2698b83661d64c (diff) | |
parent | d9d83f1d92b696ef56f4944df036b8a78364ebb4 (diff) | |
download | mariadb-git-213ece2f2e8c23ee0e727cc02dcecfae6f510ca2.tar.gz |
Merge 10.1 into 10.1
This is joint work with Oleksandr Byelkin.
Diffstat (limited to 'sql/mysql_install_db.cc')
-rw-r--r-- | sql/mysql_install_db.cc | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index e0f6ed4daa8..01d00855aed 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -27,6 +27,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" \ @@ -549,20 +551,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 @@ -675,7 +735,7 @@ static int create_db_instance() } end: - if (ret) + if (ret && cleanup_datadir) { SetCurrentDirectory(cwd); clean_directory(opt_datadir); |