From 448772b73ee690c303ca0de98ba5b619df8dfb51 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 5 Nov 2021 10:28:33 +0000 Subject: [PATCH] Wait for device reboot when using fwupdtool detach --- src/fu-tool.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/fu-tool.c b/src/fu-tool.c index 13d739537..76ff8f6d0 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -26,6 +26,7 @@ #include "fu-cabinet.h" #include "fu-context-private.h" #include "fu-debug.h" +#include "fu-device-list.h" #include "fu-device-private.h" #include "fu-engine.h" #include "fu-history.h" @@ -1521,6 +1522,7 @@ static gboolean fu_util_detach(FuUtilPrivate *priv, gchar **values, GError **error) { g_autoptr(FuDevice) device = NULL; + g_autoptr(FuDeviceList) device_list = fu_device_list_new(); g_autoptr(FuDeviceLocker) locker = NULL; /* load engine */ @@ -1545,7 +1547,18 @@ fu_util_detach(FuUtilPrivate *priv, gchar **values, GError **error) locker = fu_device_locker_new(device, error); if (locker == NULL) return FALSE; - return fu_device_detach_full(device, priv->progress, error); + fu_device_list_add(device_list, device); + if (!fu_device_detach_full(device, priv->progress, error)) + return FALSE; + + /* wait for replug */ + if (!priv->no_safety_check) { + if (!fu_device_list_wait_for_replug(device_list, error)) + return FALSE; + } + + /* success */ + return TRUE; } static gboolean @@ -1618,6 +1631,7 @@ static gboolean fu_util_attach(FuUtilPrivate *priv, gchar **values, GError **error) { g_autoptr(FuDevice) device = NULL; + g_autoptr(FuDeviceList) device_list = fu_device_list_new(); g_autoptr(FuDeviceLocker) locker = NULL; /* load engine */ @@ -1642,7 +1656,18 @@ fu_util_attach(FuUtilPrivate *priv, gchar **values, GError **error) locker = fu_device_locker_new(device, error); if (locker == NULL) return FALSE; - return fu_device_attach_full(device, priv->progress, error); + fu_device_list_add(device_list, device); + if (!fu_device_attach_full(device, priv->progress, error)) + return FALSE; + + /* wait for replug */ + if (!priv->no_safety_check) { + if (!fu_device_list_wait_for_replug(device_list, error)) + return FALSE; + } + + /* success */ + return TRUE; } static gboolean