mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 01:03:14 +02:00
core, plugins: abort upgrade immediately if any upgrade file fails to be written
Detail of changes: - the save of upgrade files in plugins is now done as soon as the "upgrade" signal is received, and not when the plugin is unloaded (it was too late to detect any problem and prevent the upgrade to happen) - if the write of an upgrade file fails, the signal callback in plugin now returns WEECHAT_RC_ERROR and WeeChat checks this code to stop the upgrade as soon as this return code is received - a new flag is added in plugin structure: unload_with_upgrade, it is set to 1 before unloading all plugins when upgrade will happen (all *.upgrade files are then already successfully written).
This commit is contained in:
@@ -199,7 +199,7 @@ irc_buffer_close_cb (const void *pointer, void *data,
|
||||
IRC_SERVER_OPTION_AUTOJOIN_DYNAMIC)
|
||||
&& ptr_server->is_connected
|
||||
&& !irc_signal_quit_received
|
||||
&& !irc_signal_upgrade_received)
|
||||
&& !weechat_irc_plugin->unload_with_upgrade)
|
||||
{
|
||||
irc_join_remove_channel_from_autojoin (ptr_server,
|
||||
ptr_channel->name);
|
||||
|
||||
@@ -452,7 +452,8 @@ irc_notify_free (struct t_irc_server *server, struct t_irc_notify *notify,
|
||||
if (notify->nick)
|
||||
{
|
||||
if ((server->monitor > 0) && remove_monitor
|
||||
&& (server->is_connected) && !irc_signal_upgrade_received)
|
||||
&& (server->is_connected)
|
||||
&& !weechat_irc_plugin->unload_with_upgrade)
|
||||
{
|
||||
/* remove one monitored nick */
|
||||
irc_server_sendf (notify->server,
|
||||
@@ -491,7 +492,7 @@ irc_notify_free_all (struct t_irc_server *server)
|
||||
{
|
||||
/* remove all monitored nicks */
|
||||
if ((server->monitor > 0) && (server->is_connected)
|
||||
&& !irc_signal_upgrade_received)
|
||||
&& !weechat_irc_plugin->unload_with_upgrade)
|
||||
{
|
||||
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL,
|
||||
"MONITOR C");
|
||||
|
||||
@@ -2411,7 +2411,7 @@ irc_server_free (struct t_irc_server *server)
|
||||
* (only if we are not in a /upgrade, because during upgrade we want to
|
||||
* keep connections and closing server buffer would disconnect from server)
|
||||
*/
|
||||
if (server->buffer && !irc_signal_upgrade_received)
|
||||
if (server->buffer && !weechat_irc_plugin->unload_with_upgrade)
|
||||
weechat_buffer_close (server->buffer);
|
||||
|
||||
/* remove server from queue */
|
||||
|
||||
+18
-7
@@ -61,7 +61,6 @@ struct t_weechat_plugin *weechat_irc_plugin = NULL;
|
||||
struct t_hook *irc_hook_timer = NULL;
|
||||
|
||||
int irc_signal_quit_received = 0; /* signal "quit" received? */
|
||||
int irc_signal_upgrade_received = 0; /* signal "upgrade" received? */
|
||||
|
||||
|
||||
/*
|
||||
@@ -121,12 +120,17 @@ irc_signal_upgrade_cb (const void *pointer, void *data,
|
||||
* save session with a disconnected state in servers and a scheduled
|
||||
* reconnection
|
||||
*/
|
||||
irc_upgrade_save (1);
|
||||
if (!irc_upgrade_save (1))
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: failed to save upgrade data"),
|
||||
weechat_prefix ("error"), IRC_PLUGIN_NAME);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
irc_signal_upgrade_received = 1;
|
||||
|
||||
quit = (signal_data && (strcmp (signal_data, "quit") == 0));
|
||||
|
||||
tls_disconnected = 0;
|
||||
@@ -178,6 +182,15 @@ irc_signal_upgrade_cb (const void *pointer, void *data,
|
||||
tls_disconnected);
|
||||
}
|
||||
|
||||
if (!irc_upgrade_save (0))
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: failed to save upgrade data"),
|
||||
weechat_prefix ("error"), IRC_PLUGIN_NAME);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -194,7 +207,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
weechat_plugin = plugin;
|
||||
|
||||
irc_signal_quit_received = 0;
|
||||
irc_signal_upgrade_received = 0;
|
||||
|
||||
irc_color_init ();
|
||||
|
||||
@@ -323,10 +335,9 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
|
||||
irc_hook_timer = NULL;
|
||||
}
|
||||
|
||||
if (irc_signal_upgrade_received)
|
||||
if (weechat_irc_plugin->unload_with_upgrade)
|
||||
{
|
||||
irc_config_write (1);
|
||||
irc_upgrade_save (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -28,6 +28,5 @@
|
||||
extern struct t_weechat_plugin *weechat_irc_plugin;
|
||||
|
||||
extern int irc_signal_quit_received;
|
||||
extern int irc_signal_upgrade_received;
|
||||
|
||||
#endif /* WEECHAT_PLUGIN_IRC_H */
|
||||
|
||||
Reference in New Issue
Block a user