examples/clear-storage: Cleanup code and use better error handling

This commit is contained in:
Marco Trevisan (Treviño)
2025-02-20 15:34:02 +01:00
parent aa18595ec7
commit 817281f6fd
3 changed files with 28 additions and 9 deletions

View File

@@ -87,10 +87,10 @@ on_clear_storage_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
} }
else else
{ {
int r = clear_saved_prints (); if (!clear_saved_prints (&error))
if (r < 0)
{ {
g_warning ("Clear saved prints from local storage failed, code %d", r); g_warning ("Clear saved prints from local storage failed: %s",
error->message);
clear_storage_data->ret_value = EXIT_FAILURE; clear_storage_data->ret_value = EXIT_FAILURE;
} }
else else
@@ -110,9 +110,11 @@ start_clear_storage (FpDevice *dev, ClearStorageData *clear_storage_data)
g_print ("Clear device storage? [Y/n]? "); g_print ("Clear device storage? [Y/n]? ");
if (fgets (buffer, sizeof (buffer), stdin) && if (fgets (buffer, sizeof (buffer), stdin) &&
(buffer[0] == 'Y' || buffer[0] == 'y' || buffer[0] == '\n')) (buffer[0] == 'Y' || buffer[0] == 'y'))
{ {
fp_device_clear_storage (dev, clear_storage_data->cancellable, (GAsyncReadyCallback) on_clear_storage_completed, clear_storage_data); fp_device_clear_storage (dev, clear_storage_data->cancellable,
(GAsyncReadyCallback) on_clear_storage_completed,
clear_storage_data);
return; return;
} }

View File

@@ -209,10 +209,24 @@ gallery_data_load (FpDevice *dev)
return gallery; return gallery;
} }
int gboolean
clear_saved_prints (void) clear_saved_prints (GError **error)
{ {
return g_remove (STORAGE_FILE); if (g_remove (STORAGE_FILE) < 0)
{
int errsv = errno;
g_set_error (error,
G_IO_ERROR,
g_io_error_from_errno (errsv),
"Error clearing storage file “%s”: %s",
STORAGE_FILE,
g_strerror (errsv));
return FALSE;
}
return TRUE;
} }
FpPrint * FpPrint *

View File

@@ -20,13 +20,16 @@
#pragma once #pragma once
#include <glib.h>
#include <libfprint/fprint.h>
int print_data_save (FpPrint *print, int print_data_save (FpPrint *print,
FpFinger finger, FpFinger finger,
gboolean update_fingerprint); gboolean update_fingerprint);
FpPrint * print_data_load (FpDevice *dev, FpPrint * print_data_load (FpDevice *dev,
FpFinger finger); FpFinger finger);
GPtrArray * gallery_data_load (FpDevice *dev); GPtrArray * gallery_data_load (FpDevice *dev);
int clear_saved_prints (void); gboolean clear_saved_prints (GError **error);
FpPrint * print_create_template (FpDevice *dev, FpPrint * print_create_template (FpDevice *dev,
FpFinger finger, FpFinger finger,
const gboolean load_existing); const gboolean load_existing);