From 027ac8d843ca258f19363d4640080707ab5cd0f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Fri, 17 Jan 2020 16:51:48 +0100
Subject: [PATCH] fpi-device: Only mark a device as closed if the operation
 succeeded

We may fail during the close phase, in such case the device should not be
marked as closed.
---
 libfprint/fpi-device.c  | 14 +++++++++-----
 tests/test-fpi-device.c |  1 +
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/libfprint/fpi-device.c b/libfprint/fpi-device.c
index 6e2f1c2..88d752a 100644
--- a/libfprint/fpi-device.c
+++ b/libfprint/fpi-device.c
@@ -851,8 +851,6 @@ fpi_device_close_complete (FpDevice *device, GError *error)
   g_debug ("Device reported close completion");
 
   clear_device_cancel_action (device);
-  priv->is_open = FALSE;
-  g_object_notify (G_OBJECT (device), "open");
 
   switch (priv->type)
     {
@@ -877,10 +875,16 @@ fpi_device_close_complete (FpDevice *device, GError *error)
     }
 
   if (!error)
-    fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_BOOL,
-                                    GUINT_TO_POINTER (TRUE));
+    {
+      priv->is_open = FALSE;
+      g_object_notify (G_OBJECT (device), "open");
+      fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_BOOL,
+                                      GUINT_TO_POINTER (TRUE));
+    }
   else
-    fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_ERROR, error);
+    {
+      fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_ERROR, error);
+    }
 }
 
 /**
diff --git a/tests/test-fpi-device.c b/tests/test-fpi-device.c
index cd1cda6..f234e50 100644
--- a/tests/test-fpi-device.c
+++ b/tests/test-fpi-device.c
@@ -386,6 +386,7 @@ test_driver_close_error (void)
   g_assert (fake_dev->last_called_function == dev_class->close);
   g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
   g_assert (error == g_steal_pointer (&fake_dev->ret_error));
+  g_assert_true (fp_device_is_open (device));
 }
 
 static void