Thread (2 messages) flat view 2 messages, 2 authors, 2021-08-25
STALE1850d

[PATCH BlueZ] device: delete cache file when device is removed

From: David Lechner <david@lechnology.com>
Date: 2021-08-25 17:29:51
Subsystem: the rest · Maintainer: Linus Torvalds

When a device is removed from BlueZ, it should be completely forgotten
so that when it is seen again, it behaves exactly the same as if this
was the first time the device was ever seen.

So instead of just deleting one section of the cache file, we delete
the entire file.

This fixes issues with the GATT cache being retained and used for
devices that don't have ServicesChanged or Database Hash characteristics
to indicate that the attributes on the device have changed.

Issue: https://github.com/bluez/bluez/issues/191
Signed-off-by: David Lechner <david@lechnology.com>
---
 src/device.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/src/device.c b/src/device.c
index 6d534c488..b51d9df4d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4485,9 +4485,6 @@ static void device_remove_stored(struct btd_device *device)
 {
 	char device_addr[18];
 	char filename[PATH_MAX];
-	GKeyFile *key_file;
-	char *data;
-	gsize length = 0;
 
 	if (device->bredr_state.bonded)
 		device_remove_bonding(device, BDADDR_BREDR);
@@ -4511,19 +4508,7 @@ static void device_remove_stored(struct btd_device *device)
 	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s",
 				btd_adapter_get_storage_dir(device->adapter),
 				device_addr);
-
-	key_file = g_key_file_new();
-	g_key_file_load_from_file(key_file, filename, 0, NULL);
-	g_key_file_remove_group(key_file, "ServiceRecords", NULL);
-
-	data = g_key_file_to_data(key_file, &length, NULL);
-	if (length > 0) {
-		create_file(filename, 0600);
-		g_file_set_contents(filename, data, length, NULL);
-	}
-
-	g_free(data);
-	g_key_file_free(key_file);
+	unlink(filename);
 }
 
 void device_remove(struct btd_device *device, gboolean remove_stored)
-- 
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help