From: "Frédéric Danis" <frederic.danis@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 06/15] device: Delete storage device recursively
Date: Thu, 13 Dec 2012 21:39:21 +0100 [thread overview]
Message-ID: <1355431170-12897-6-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1355431170-12897-1-git-send-email-frederic.danis@linux.intel.com>
Device storage directory may contain multiple files like info or
attributes but also files stored by plug-ins or profiles,
so completely delete directory.
---
src/device.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/device.c b/src/device.c
index 42a7c65..36bf9bc 100644
--- a/src/device.c
+++ b/src/device.c
@@ -34,6 +34,7 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <errno.h>
+#include <dirent.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/uuid.h>
@@ -2031,6 +2032,34 @@ uint16_t btd_device_get_version(struct btd_device *device)
return device->version;
}
+static void delete_folder_tree(const char *dirname)
+{
+ DIR *dir;
+ struct dirent *entry;
+ char filename[PATH_MAX + 1];
+
+ dir = opendir(dirname);
+ if (dir == NULL)
+ return;
+
+ while ((entry = readdir(dir)) != NULL) {
+ if (g_str_equal(entry->d_name, ".") ||
+ g_str_equal(entry->d_name, ".."))
+ continue;
+
+ snprintf(filename, PATH_MAX, "%s/%s", dirname, entry->d_name);
+ filename[PATH_MAX] = '\0';
+
+ if (entry->d_type == DT_DIR)
+ delete_folder_tree(filename);
+ else
+ unlink(filename);
+ }
+ closedir(dir);
+
+ rmdir(dirname);
+}
+
static void device_remove_stored(struct btd_device *device)
{
const bdaddr_t *src = adapter_get_address(device->adapter);
@@ -2062,15 +2091,10 @@ static void device_remove_stored(struct btd_device *device)
ba2str(src, adapter_addr);
ba2str(&device->bdaddr, device_addr);
- snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
- device_addr);
- filename[PATH_MAX] = '\0';
- remove(filename);
-
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", adapter_addr,
device_addr);
filename[PATH_MAX] = '\0';
- remove(filename);
+ delete_folder_tree(filename);
}
void device_remove(struct btd_device *device, gboolean remove_stored)
--
1.7.9.5
next prev parent reply other threads:[~2012-12-13 20:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-13 20:39 [PATCH v2 01/15] device: Retrieve device technology from storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 02/15] device: Add device_create_from_storage() function Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 03/15] adapter: Convert device profiles list Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 04/15] device: Load profiles from storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 05/15] adapter: Probe profiles after device creation Frédéric Danis
2012-12-13 20:39 ` Frédéric Danis [this message]
2012-12-13 20:39 ` [PATCH v2 07/15] doc: Update Settings-storage for SDP records Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 08/15] adapter: Convert device sdp file Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 09/15] device: Remove stored SDP records on device removal Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 10/15] device: Load primary attributes from storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 11/15] device: Store SDP records in new storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 12/15] adapter: Convert device primaries list Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 13/15] adapter: Remove create_stored_device_from_primaries Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 14/15] device: Update btd_device_get_record to use new storage Frédéric Danis
2012-12-13 20:39 ` [PATCH v2 15/15] input: Use new storage architecture Frédéric Danis
2012-12-14 8:31 ` [PATCH v2 01/15] device: Retrieve device technology from storage Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1355431170-12897-6-git-send-email-frederic.danis@linux.intel.com \
--to=frederic.danis@linux.intel.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).