After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 612145 - iPod Plugin: /* FIXME: should create a unique filename */
iPod Plugin: /* FIXME: should create a unique filename */
Status: RESOLVED DUPLICATE of bug 570600
Product: rhythmbox
Classification: Other
Component: iPod
unspecified
Other All
: Normal normal
: ---
Assigned To: RhythmBox Maintainers
RhythmBox Maintainers
: 609609 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-03-08 00:11 UTC by Koichi Akabe
Modified: 2010-03-19 22:54 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Koichi Akabe 2010-03-08 00:11:24 UTC
rhythmbox-0.12.7/plugins/ipod/rb-ipod-source.c
in the function: generate_ipod_filename

There is a comment: "/* FIXME: should create a unique filename */"
So I can't download a lot of same named files.

For example:
CD 1: "Track 1"
CD 2: "Track 1"
Two files are named "Track 1"

If they are changed to the following code, this problem will be solved. (generate_ipod_filename, ipod_get_filename_for_uri)

====

static gchar *
generate_ipod_filename (const gchar *mount_point, const gchar *extension)
{
    gchar *ipod_filename = NULL;
    gchar *rand_filename;
    gchar *random_str;
    gint tries = 0;
    gint i;
    FILE *fp;
    /* Make a random file name */
    random_str = g_malloc (sizeof (gchar) * 9);
    for (;;) {
        random_str[8] = 0;
        for (i = 7; i >= 0; i--)
            random_str[i] = 'A' + g_random_int_range (0, 26);
        rand_filename = g_strdup_printf ("%s.%s", random_str, extension);
        /* Now we have a random filename, try to find out where to put
         * it on the iPod
         */
        do {
            g_free (ipod_filename);
            ipod_filename = get_ipod_filename (mount_point, rand_filename);
            tries++;
            if (tries > MAX_TRIES) {
                g_free(rand_filename);
                g_free(random_str);
                return NULL;
            }
        } while ((ipod_filename == NULL) || (g_file_test (ipod_filename, G_FILE_TEST_EXISTS)));
        /* If ipod_filename already exist, re-create a random filename. */
        fp = fopen(ipod_filename, "rb");
        if(fp == NULL)
            break;
        fclose(fp);
    }
    g_free(rand_filename);
    g_free(random_str);
    return ipod_filename;
}

static gchar *
ipod_get_filename_for_uri (const gchar *mount_point,
			   const gchar *uri_str,
			   const gchar *mimetype,
			   const gchar *extension)
{
	gchar *result;

	/* FIXME: we really need a mapping (audio/mpeg->mp3) and not
	 * just rely on the user's audio profile havign the "right" one */

	result = generate_ipod_filename (mount_point, extension);
	return result;
}

/* End of generation of the filename on the iPod */
Comment 1 Jonathan Matthew 2010-03-08 00:14:34 UTC
You already reported this bug.

*** This bug has been marked as a duplicate of bug 609609 ***
Comment 2 Christophe Fergeau 2010-03-19 22:41:42 UTC
This one has what can be seen as a patch
Comment 3 Christophe Fergeau 2010-03-19 22:42:03 UTC
*** Bug 609609 has been marked as a duplicate of this bug. ***
Comment 4 Christophe Fergeau 2010-03-19 22:54:42 UTC
bug #442137 is about using random filenames as you suggest for the iPod. Bug #570600 is about remaining duplicate filename issues in Rhythmbox, so I'll close this bug as a duplicate. I added a link to your suggested code in bug #442137

*** This bug has been marked as a duplicate of bug 570600 ***