commit 818d07b74adb2c9b74aa79492f45167783a12199
Author: Christophe Fergeau <[email protected]>
Date: Tue Jun 15 22:10:07 2010 +0200
create Device directory if it's missing
tools/read-sysinfoextended.c | 68 +++++++++++++++++++++++++----------------
1 files changed, 41 insertions(+), 27 deletions(-)
---
diff --git a/tools/read-sysinfoextended.c b/tools/read-sysinfoextended.c
index b4c71c1..bf789ce 100644
--- a/tools/read-sysinfoextended.c
+++ b/tools/read-sysinfoextended.c
@@ -25,6 +25,7 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include <glib/gstdio.h>
#include <stdlib.h>
#include "itdb.h"
@@ -38,6 +39,39 @@ extern char *read_sysinfo_extended_by_uuid (const char
*uuid);
extern char *read_sysinfo_extended_from_usb (guint bus_number, guint
device_address);
#endif
+static gboolean write_sysinfo_extended (const char *mountpoint,
+ const char *data)
+{
+ char *filename;
+ char *devdirpath;
+ gboolean result;
+
+ devdirpath = itdb_get_device_dir (mountpoint);
+ /* Make sure the device dir exists (not necessarily true on
+ * Shuffles */
+ if (devdirpath == NULL) {
+ gchar *itunesdirpath;
+
+ itunesdirpath = itdb_get_itunes_dir (mountpoint);
+ if (itunesdirpath == NULL) {
+ return FALSE;
+ }
+ devdirpath = g_build_filename (itunesdirpath, "Device", NULL);
+ g_free (itunesdirpath);
+ g_mkdir (devdirpath, 0777);
+ }
+ filename = g_build_filename (devdirpath, "SysInfoExtended", NULL);
+ g_free (devdirpath);
+ if (filename == NULL) {
+ return FALSE;
+ }
+
+ result = g_file_set_contents (filename, data, -1, NULL);
+ g_free (filename);
+
+ return result;
+}
+
int
main (int argc, char **argv)
{
@@ -86,34 +120,14 @@ main (int argc, char **argv)
return 1;
} else {
const char *mountpoint = argv[argc-1];
- char *device_path;
- char *filename;
- gboolean success;
-
- device_path = itdb_get_device_dir (mountpoint);
- if (device_path == NULL) {
- g_free (xml);
- g_print (_("Couldn't resolve Device directory path on %s\n"),
- mountpoint);
- return 1;
- }
-
- filename = g_build_filename (device_path, "SysInfoExtended", NULL);
- g_free (device_path);
- if (filename == NULL) {
- g_print (_("Couldn't resolve SysInfoExtended path on %s"),
- mountpoint);
- g_free (xml);
- return 1;
- }
+ gboolean success;
- success = g_file_set_contents (filename, xml, -1, NULL);
- g_free (xml);
- g_free (filename);
- if (!success) {
- g_print (_("Couldn't write SysInfoExtended to %s"), mountpoint);
- return 1;
- }
+ success = write_sysinfo_extended (mountpoint, xml);
+ g_free (xml);
+ if (!success) {
+ g_print (_("Couldn't write SysInfoExtended to %s"), mountpoint);
+ return 1;
+ }
}
return 0;
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2