Commit 874e4e47 authored by Monty's avatar Monty Committed by Sergei Golubchik

Better error message for mysql_upgrade if upgrade file can't be updated.

parent b6c5657e
...@@ -673,7 +673,7 @@ static int get_upgrade_info_file_name(char* name) ...@@ -673,7 +673,7 @@ static int get_upgrade_info_file_name(char* name)
*/ */
static int upgrade_already_done(void) static int upgrade_already_done(myf flags)
{ {
FILE *in; FILE *in;
char upgrade_info_file[FN_REFLEN]= {0}; char upgrade_info_file[FN_REFLEN]= {0};
...@@ -681,17 +681,23 @@ static int upgrade_already_done(void) ...@@ -681,17 +681,23 @@ static int upgrade_already_done(void)
if (get_upgrade_info_file_name(upgrade_info_file)) if (get_upgrade_info_file_name(upgrade_info_file))
return 0; /* Could not get filename => not sure */ return 0; /* Could not get filename => not sure */
if (!(in= my_fopen(upgrade_info_file, O_RDONLY, MYF(0)))) if (!(in= my_fopen(upgrade_info_file, O_RDONLY, flags)))
return 0; /* Could not open file => not sure */ return 0; /* Could not open file => not sure */
bzero(upgrade_from_version, sizeof(upgrade_from_version)); bzero(upgrade_from_version, sizeof(upgrade_from_version));
if (!fgets(upgrade_from_version, sizeof(upgrade_from_version), in)) if (!fgets(upgrade_from_version, sizeof(upgrade_from_version), in))
{ {
/* Ignore, will be detected by strncmp() below */ /* Preserve errno for caller */
int save_errno= errno;
(void) my_fclose(in, flags);
errno= save_errno;
return 0;
} }
my_fclose(in, MYF(0)); if (my_fclose(in, flags))
return 0;
errno= 0;
return (strncmp(upgrade_from_version, MYSQL_SERVER_VERSION, return (strncmp(upgrade_from_version, MYSQL_SERVER_VERSION,
sizeof(MYSQL_SERVER_VERSION)-1)==0); sizeof(MYSQL_SERVER_VERSION)-1)==0);
} }
...@@ -720,23 +726,24 @@ static void create_mysql_upgrade_info_file(void) ...@@ -720,23 +726,24 @@ static void create_mysql_upgrade_info_file(void)
{ {
fprintf(stderr, fprintf(stderr,
"Could not create the upgrade info file '%s' in " "Could not create the upgrade info file '%s' in "
"the MySQL Servers datadir, errno: %d\n", "the MariaDB Servers datadir, errno: %d\n",
upgrade_info_file, errno); upgrade_info_file, errno);
return; return;
} }
/* Write new version to file */ /* Write new version to file */
fputs(MYSQL_SERVER_VERSION, out); my_fwrite(out, (uchar*) MYSQL_SERVER_VERSION,
my_fclose(out, MYF(0)); sizeof(MYSQL_SERVER_VERSION), MY_WME);
my_fclose(out, MYF(MY_WME));
/* /*
Check if the upgrad_info_file was properly created/updated Check if the upgrad_info_file was properly created/updated
It's not a fatal error -> just print a message if it fails It's not a fatal error -> just print a message if it fails
*/ */
if (!upgrade_already_done()) if (!upgrade_already_done(MY_WME))
fprintf(stderr, fprintf(stderr,
"Could not write to the upgrade info file '%s' in " "Upgrade file '%s' was not properly created. "
"the MySQL Servers datadir, errno: %d\n", "Got error errno while checking file content: %d\n",
upgrade_info_file, errno); upgrade_info_file, errno);
return; return;
} }
...@@ -1191,7 +1198,7 @@ int main(int argc, char **argv) ...@@ -1191,7 +1198,7 @@ int main(int argc, char **argv)
Read the mysql_upgrade_info file to check if mysql_upgrade Read the mysql_upgrade_info file to check if mysql_upgrade
already has been run for this installation of MySQL already has been run for this installation of MySQL
*/ */
if (!opt_force && upgrade_already_done()) if (!opt_force && upgrade_already_done(0))
{ {
printf("This installation of MySQL is already upgraded to %s, " printf("This installation of MySQL is already upgraded to %s, "
"use --force if you still need to run mysql_upgrade\n", "use --force if you still need to run mysql_upgrade\n",
......
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