From 8ba58a2e440acc485ca2ea7003f259376336d36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= Date: Thu, 19 Jan 2023 17:54:12 +0100 Subject: Save removed devices in JSON dump only when requested Removed devices should not be saved when trying dump events per update phase. --- gusb/gusb-context.c | 10 ++++++---- gusb/gusb-context.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c index 6e8d82f..f6a52c8 100644 --- a/gusb/gusb-context.c +++ b/gusb/gusb-context.c @@ -486,10 +486,12 @@ g_usb_context_save_with_tag(GUsbContext *self, /* array of devices */ json_builder_set_member_name(json_builder, "UsbDevices"); json_builder_begin_array(json_builder); - for (guint i = 0; i < priv->devices_removed->len; i++) { - GUsbDevice *device = g_ptr_array_index(priv->devices_removed, i); - if (!_g_usb_device_save(device, json_builder, error)) - return FALSE; + if (priv->flags & G_USB_CONTEXT_FLAGS_SAVE_REMOVED_DEVICES) { + for (guint i = 0; i < priv->devices_removed->len; i++) { + GUsbDevice *device = g_ptr_array_index(priv->devices_removed, i); + if (!_g_usb_device_save(device, json_builder, error)) + return FALSE; + } } for (guint i = 0; i < priv->devices->len; i++) { GUsbDevice *device = g_ptr_array_index(priv->devices, i); diff --git a/gusb/gusb-context.h b/gusb/gusb-context.h index f633520..b1542da 100644 --- a/gusb/gusb-context.h +++ b/gusb/gusb-context.h @@ -41,6 +41,7 @@ typedef enum { G_USB_CONTEXT_FLAGS_NONE = 0, G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES = 1 << 0, G_USB_CONTEXT_FLAGS_SAVE_EVENTS = 1 << 1, + G_USB_CONTEXT_FLAGS_SAVE_REMOVED_DEVICES = 1 << 2, /*< private >*/ G_USB_CONTEXT_FLAGS_LAST } GUsbContextFlags; -- cgit v1.2.1