summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2020-06-30 12:45:37 +0200
committerVladislav Vaintroub <wlad@mariadb.com>2020-07-01 13:03:51 +0200
commitfe05c16c8d6d9ff90186578cdc3db460469e4fe1 (patch)
tree545e99fdcfbac1a2bf962f2253d8bd163b702e0a
parent1ea266f3ef36e779d23697b18cb94e1b0f8e65ef (diff)
downloadmariadb-git-fe05c16c8d6d9ff90186578cdc3db460469e4fe1.tar.gz
MDEV-23052 mysql_install_db.exe can run on existing non-empty directory,
and remove it on error Disable existing non-empty datadir for mysql_install_db.exe
-rw-r--r--sql/mysql_install_db.cc22
1 files changed, 15 insertions, 7 deletions
diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc
index c6912e41f6e..022ba18a3e3 100644
--- a/sql/mysql_install_db.cc
+++ b/sql/mysql_install_db.cc
@@ -399,8 +399,8 @@ static int register_service()
static void clean_directory(const char *dir)
{
- char dir2[MAX_PATH+2];
- *(strmake_buf(dir2, dir)+1)= 0;
+ char dir2[MAX_PATH + 4]= {};
+ snprintf(dir2, MAX_PATH+2, "%s\\*", dir);
SHFILEOPSTRUCT fileop;
fileop.hwnd= NULL; /* no status display */
@@ -551,7 +551,7 @@ static int create_db_instance()
DWORD cwd_len= MAX_PATH;
char cmdline[3*MAX_PATH];
FILE *in;
- bool cleanup_datadir= true;
+ bool created_datadir= false;
DWORD last_error;
verbose("Running bootstrap");
@@ -560,7 +560,11 @@ static int create_db_instance()
/* Create datadir and datadir/mysql, if they do not already exist. */
- if (!CreateDirectory(opt_datadir, NULL) && (GetLastError() != ERROR_ALREADY_EXISTS))
+ if (CreateDirectory(opt_datadir, NULL))
+ {
+ created_datadir= true;
+ }
+ else if (GetLastError() != ERROR_ALREADY_EXISTS)
{
last_error = GetLastError();
switch(last_error)
@@ -597,9 +601,11 @@ static int create_db_instance()
}
}
- if (PathIsDirectoryEmpty(opt_datadir))
+ if (!PathIsDirectoryEmpty(opt_datadir))
{
- cleanup_datadir= false;
+ fprintf(stderr,"ERROR : Data directory %s is not empty."
+ " Only new or empty existing directories are accepted for --datadir\n",opt_datadir);
+ exit(1);
}
if (!CreateDirectory("mysql",NULL))
@@ -735,10 +741,12 @@ static int create_db_instance()
}
end:
- if (ret && cleanup_datadir)
+ if (ret)
{
SetCurrentDirectory(cwd);
clean_directory(opt_datadir);
+ if (created_datadir)
+ RemoveDirectory(opt_datadir);
}
return ret;
}