@@ -399,8 +399,8 @@ static int register_service()
399
399
400
400
static void clean_directory (const char *dir)
401
401
{
402
- char dir2[MAX_PATH+ 2 ] ;
403
- *( strmake_buf ( dir2, dir)+ 1 )= 0 ;
402
+ char dir2[MAX_PATH + 4 ]= {} ;
403
+ snprintf ( dir2, MAX_PATH+ 2 , " %s \\ * " , dir) ;
404
404
405
405
SHFILEOPSTRUCT fileop;
406
406
fileop.hwnd = NULL ; /* no status display */
@@ -551,7 +551,7 @@ static int create_db_instance()
551
551
DWORD cwd_len= MAX_PATH;
552
552
char cmdline[3 *MAX_PATH];
553
553
FILE *in;
554
- bool cleanup_datadir= true ;
554
+ bool created_datadir= false ;
555
555
DWORD last_error;
556
556
557
557
verbose (" Running bootstrap" );
@@ -560,7 +560,11 @@ static int create_db_instance()
560
560
561
561
/* Create datadir and datadir/mysql, if they do not already exist. */
562
562
563
- if (!CreateDirectory (opt_datadir, NULL ) && (GetLastError () != ERROR_ALREADY_EXISTS))
563
+ if (CreateDirectory (opt_datadir, NULL ))
564
+ {
565
+ created_datadir= true ;
566
+ }
567
+ else if (GetLastError () != ERROR_ALREADY_EXISTS)
564
568
{
565
569
last_error = GetLastError ();
566
570
switch (last_error)
@@ -597,9 +601,11 @@ static int create_db_instance()
597
601
}
598
602
}
599
603
600
- if (PathIsDirectoryEmpty (opt_datadir))
604
+ if (! PathIsDirectoryEmpty (opt_datadir))
601
605
{
602
- cleanup_datadir= false ;
606
+ fprintf (stderr," ERROR : Data directory %s is not empty."
607
+ " Only new or empty existing directories are accepted for --datadir\n " ,opt_datadir);
608
+ exit (1 );
603
609
}
604
610
605
611
if (!CreateDirectory (" mysql" ,NULL ))
@@ -735,10 +741,12 @@ static int create_db_instance()
735
741
}
736
742
737
743
end:
738
- if (ret && cleanup_datadir )
744
+ if (ret)
739
745
{
740
746
SetCurrentDirectory (cwd);
741
747
clean_directory (opt_datadir);
748
+ if (created_datadir)
749
+ RemoveDirectory (opt_datadir);
742
750
}
743
751
return ret;
744
752
}
0 commit comments