Permalink
Browse files

Add and use a function to save the MySQL version number

  • Loading branch information...
1 parent ad381d1 commit 1fd2f398adc47dd8b5f3bef1967e452342314a15 @jcameron jcameron committed Dec 27, 2016
Showing with 18 additions and 11 deletions.
  1. +18 −11 mysql/mysql-lib.pl
View
@@ -27,10 +27,8 @@
$mysql_login = $userconfig{'login'};
$mysql_pass = $userconfig{'pass'};
}
- if (open(VERSION, "$user_module_config_directory/version")) {
- chop($mysql_version = <VERSION>);
- close(VERSION);
- }
+ chop($mysql_version = &read_file_contents(
+ "$user_module_config_directory/version"));
$max_dbs = $userconfig{'max_dbs'};
$commands_file = "$user_module_config_directory/commands";
$sql_charset = $userconfig{'charset'};
@@ -48,13 +46,9 @@
$mysql_login = $config{'login'};
$mysql_pass = $config{'pass'};
}
- if (open(VERSION, "$module_config_directory/version")) {
- chop($mysql_version = <VERSION>);
- close(VERSION);
- }
- else {
- $mysql_version = &get_mysql_version();
- }
+ chop($mysql_version = &read_file_contents(
+ "$module_config_directory/version"));
+ $mysql_version ||= &get_mysql_version();
$cron_cmd = "$module_config_directory/backup.pl";
$max_dbs = $config{'max_dbs'};
$commands_file = "$module_config_directory/commands";
@@ -815,6 +809,19 @@ sub get_remote_mysql_version
return $data->{'data'}->[0]->[0];
}
+# save_mysql_version([number])
+# Update the saved local MySQL version number
+sub save_mysql_version
+{
+local ($ver) = @_;
+$ver ||= &get_mysql_version();
+if ($ver) {
+ &open_tempfile(VERSION, ">$module_config_directory/version");
+ &print_tempfile(VERSION, $ver,"\n");
+ &close_tempfile(VERSION);
+ }
+}
+
# date_subs(filename)
# Does strftime-style date substitutions on a filename, if enabled
sub date_subs

0 comments on commit 1fd2f39

Please sign in to comment.