All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frédéric Danis" <frederic.danis@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [RFC V3 04/12] adapter: Add force dir creation to convert_file()
Date: Fri, 30 Nov 2012 15:46:58 +0100	[thread overview]
Message-ID: <1354286826-24016-4-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>

Some device information, like class or device id, should only be
converted if directory for this device has already been created
during previous conversion (from aliases, trusts, blocked, ...
files).
---
 src/adapter.c |   33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 8e3251b..a976793 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -34,6 +34,7 @@
 #include <stdbool.h>
 #include <sys/ioctl.h>
 #include <sys/file.h>
+#include <sys/stat.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/uuid.h>
@@ -2526,6 +2527,7 @@ static void convert_names_entry(char *key, char *value, void *user_data)
 struct device_converter {
 	char *address;
 	void (*cb)(GKeyFile *key_file, void *value);
+	gboolean force;
 };
 
 static void convert_aliases_entry(GKeyFile *key_file, void *value)
@@ -2601,6 +2603,19 @@ static void convert_entry(char *key, char *value, void *user_data)
 	if (bachk(key) != 0)
 		return;
 
+	if (converter->force == FALSE) {
+		struct stat st;
+		int err;
+
+		snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s",
+				converter->address, key);
+		filename[PATH_MAX] = '\0';
+
+		err = stat(filename, &st);
+		if (err || !S_ISDIR(st.st_mode))
+			return;
+	}
+
 	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
 			converter->address, key);
 	filename[PATH_MAX] = '\0';
@@ -2621,7 +2636,8 @@ static void convert_entry(char *key, char *value, void *user_data)
 }
 
 static void convert_file(char *file, char *address,
-				void (*cb)(GKeyFile *key_file, void *value))
+				void (*cb)(GKeyFile *key_file, void *value),
+				gboolean force)
 {
 	char filename[PATH_MAX + 1];
 	struct device_converter converter;
@@ -2636,6 +2652,7 @@ static void convert_file(char *file, char *address,
 	} else {
 		converter.address = address;
 		converter.cb = cb;
+		converter.force = force;
 
 		textfile_foreach(filename, convert_entry, &converter);
 		textfile_put(filename, "converted", "yes");
@@ -2665,19 +2682,19 @@ static void convert_device_storage(struct btd_adapter *adapter)
 	free(str);
 
 	/* Convert aliases */
-	convert_file("aliases", address, convert_aliases_entry);
+	convert_file("aliases", address, convert_aliases_entry, TRUE);
 
 	/* Convert trusts */
-	convert_file("trusts", address, convert_trusts_entry);
-
-	/* Convert classes */
-	convert_file("classes", address, convert_classes_entry);
+	convert_file("trusts", address, convert_trusts_entry, TRUE);
 
 	/* Convert blocked */
-	convert_file("blocked", address, convert_blocked_entry);
+	convert_file("blocked", address, convert_blocked_entry, TRUE);
+
+	/* Convert classes */
+	convert_file("classes", address, convert_classes_entry, FALSE);
 
 	/* Convert device ids */
-	convert_file("did", address, convert_did_entry);
+	convert_file("did", address, convert_did_entry, FALSE);
 }
 
 static void convert_config(struct btd_adapter *adapter, const char *filename,
-- 
1.7.9.5


  parent reply	other threads:[~2012-11-30 14:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-30 14:46 [RFC V3 01/12] doc: Update settings-storage.txt Frédéric Danis
2012-11-30 14:46 ` [RFC V3 02/12] device: Load device info before updating info file Frédéric Danis
2012-11-30 14:46 ` [RFC V3 03/12] adapter: Fix device storage creation Frédéric Danis
2012-11-30 14:46 ` Frédéric Danis [this message]
2012-11-30 14:46 ` [RFC V3 05/12] adapter: Convert device type Frédéric Danis
2012-11-30 14:47 ` [RFC V3 06/12] adapter: Load devices from new storage architecture Frédéric Danis
2012-11-30 14:47 ` [RFC V3 07/12] adapter: Convert storage linkkeys file Frédéric Danis
2012-11-30 14:47 ` [RFC V3 08/12] adapter: Upload link keys from new storage Frédéric Danis
2012-11-30 14:47 ` [RFC V3 09/12] event: Store link key infos in device info file Frédéric Danis
2012-11-30 14:47 ` [RFC V3 10/12] adapter: Convert storage longtermkeys file Frédéric Danis
2012-11-30 14:47 ` [RFC V3 11/12] adapter: Upload long term keys from new storage Frédéric Danis
2012-11-30 14:47 ` [RFC V3 12/12] event: Store long term key infos in device info file Frédéric Danis
2012-12-04  8:18 ` [RFC V3 01/12] doc: Update settings-storage.txt 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=1354286826-24016-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.