From: Yasuhiro M. <mat...@gm...> - 2014-03-06 05:23:58
|
> How about this instead? > > diff --git a/src/itdb_sqlite.c b/src/itdb_sqlite.c > index b5b2975..23c645f 100644 > --- a/src/itdb_sqlite.c > +++ b/src/itdb_sqlite.c > @@ -2278,8 +2278,9 @@ int itdb_sqlite_generate_itdbs(FExport *fexp) > > tzoffset = fexp->itdb->tzoffset; > > - tmpdir = g_build_path(g_get_tmp_dir(), tmpnam(NULL), NULL); > - if (g_mkdir(tmpdir, 0755) != 0) { > + tmpdir = g_build_path(G_DIR_SEPARATOR_S, g_get_tmp_dir(), "libgpod.XXXXXX", NULL); > + > + if (!g_mkdtemp(tmpdir)) { > g_set_error (&fexp->error, G_FILE_ERROR, g_file_error_from_errno(errno), > "Could not create temporary directory '%s': %s", > tmpdir, strerror(errno)); > > mkstemp() creates a temporary file and returns its file-handle, > according to > https://developer.gnome.org/glib/2.37/glib-File-Utilities.html#g-mkstemp > (and, I think, in common with typical mkstemp() implementations). Your > patch caused libgpod.BLAH files to be created in the CWD, as well as > /tmp/libgpod.BLAH to be created. > > It looks like mkdtemp() is what we want, though I see there's a > g_dir_make_tmp() too. > > I don't know if this will work on Windows, but I imagine it should. Docs says: "the template should only be a basename, no directory components are allowed" So patch should be https://gist.github.com/mattn/9383016 But on windows, g_dir_make_tmp() is tool newer API. So I can't build it. And g_array_set_clear_func() is also newer APIs for windows. Currently, glib for windows is version 2.28.8 . I hope to revert with below's patch. Thanks. - Yasuhiro Matsumoto diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c index a177e26..7fe178e 100644 --- a/src/itdb_itunesdb.c +++ b/src/itdb_itunesdb.c @@ -1155,7 +1155,7 @@ static gboolean playcounts_plist_read (FImport *fimp, GValue *plist_data) struct playcount *playcount; GHashTable *pc_dict, *track_dict; GValue *to_parse; - GArray *array; + GValueArray *array; gint i; guint32 mac_time; guint64 *dbid; @@ -1167,19 +1167,19 @@ static gboolean playcounts_plist_read (FImport *fimp, GValue *plist_data) if (to_parse == NULL) { return FALSE; } - if (!G_VALUE_HOLDS (to_parse, G_TYPE_ARRAY)) { + if (!G_VALUE_HOLDS (to_parse, G_TYPE_VALUE_ARRAY)) { return FALSE; } playcounts = g_hash_table_new_full (g_int64_hash, g_int64_equal, g_free, g_free); - array = (GArray*)g_value_get_boxed (to_parse); - for (i = 0; i < array->len; i++) { - if (!G_VALUE_HOLDS (g_array_index (array, GValue *, i), G_TYPE_HASH_TABLE)) { + array = (GValueArray*)g_value_get_boxed (to_parse); + for (i = 0; i < array->n_values; i++) { + if (!G_VALUE_HOLDS (g_value_array_get_nth (array, i), G_TYPE_HASH_TABLE)) { continue; } - track_dict = g_value_get_boxed (g_array_index (array, GValue *, i)); + track_dict = g_value_get_boxed (g_value_array_get_nth (array, i)); if (track_dict == NULL) continue; diff --git a/src/itdb_plist.c b/src/itdb_plist.c index 4104cb8..b0cfbf1 100644 --- a/src/itdb_plist.c +++ b/src/itdb_plist.c @@ -40,7 +40,7 @@ * - <integer> => G_TYPE_INT64 (gint64) * - <true/>, <false/> => G_TYPE_BOOLEAN (gboolean) * - <data> => G_TYPE_GSTRING (GString *) - * - <array> => G_TYPE_ARRAY (GArray *) + * - <array> => G_TYPE_VALUE_ARRAY (GValueArray *) * - <dict> => G_TYPE_HASH_TABLE (GHashTable *) */ #ifdef HAVE_CONFIG_H @@ -70,6 +70,7 @@ extern GQuark itdb_device_error_quark (void); static GValue *parse_node (xmlNode *a_node, GError **error); + static void value_free (GValue *val) { @@ -275,17 +276,17 @@ parse_array (xmlNode *a_node, GError **error) { xmlNode *cur_node = a_node->children; GValue *value; - GArray *array; + GValueArray *array; - array = g_array_new (FALSE, TRUE, sizeof(GValue)); - g_array_set_clear_func (array, (GDestroyNotify)g_value_unset); + array = g_value_array_new (4); while (cur_node != NULL) { if (get_parser_for_type (cur_node->name) != NULL) { GValue *cur_value; cur_value = parse_node (cur_node, error); if (cur_value != NULL) { - array = g_array_append_vals (array, cur_value, 1); + array = g_value_array_append (array, cur_value); + g_value_unset (cur_value); g_free (cur_value); } } @@ -298,11 +299,11 @@ parse_array (xmlNode *a_node, GError **error) } if ((error != NULL) && (*error != NULL)) { - g_array_unref (array); + g_value_array_free (array); return NULL; } value = g_new0 (GValue, 1); - value = g_value_init (value, G_TYPE_ARRAY); + value = g_value_init (value, G_TYPE_VALUE_ARRAY); g_value_take_boxed (value, array); return value; diff --git a/src/itdb_sysinfo_extended_parser.c b/src/itdb_sysinfo_extended_parser.c index 78dcf70..cc09c49 100644 --- a/src/itdb_sysinfo_extended_parser.c +++ b/src/itdb_sysinfo_extended_parser.c @@ -479,26 +479,26 @@ static GList *parse_one_formats_list (GHashTable *sysinfo_dict, { GValue *to_parse; GList *formats = NULL; - GArray *array; + GValueArray *array; gint i; to_parse = g_hash_table_lookup (sysinfo_dict, key); if (to_parse == NULL) { return NULL; } - if (!G_VALUE_HOLDS (to_parse, G_TYPE_ARRAY)) { + if (!G_VALUE_HOLDS (to_parse, G_TYPE_VALUE_ARRAY)) { return NULL; } - array = (GArray*)g_value_get_boxed (to_parse); - for (i = 0; i < array->len; i++) { + array = (GValueArray*)g_value_get_boxed (to_parse); + for (i = 0; i < array->n_values; i++) { Itdb_ArtworkFormat *format; /* SysInfoExtended on the iPhone has <string> fields in the artwork * format array in addition to the hash we parse */ - if (!G_VALUE_HOLDS (&g_array_index (array, GValue, i), G_TYPE_HASH_TABLE)) { + if (!G_VALUE_HOLDS (g_value_array_get_nth (array, i), G_TYPE_HASH_TABLE)) { continue; } - format = g_value_to_image_format (&g_array_index (array, GValue, i)); + format = g_value_to_image_format (g_value_array_get_nth (array, i)); if (format != NULL) { formats = g_list_prepend (formats, format); } |