#
# Ubuntu: https://bugs.launchpad.net/ubuntu/+source/rhythmbox/+bug/312902
# Upstream: http://bugzilla.gnome.org/show_bug.cgi?id=570600
# Description: Put a random suffix on truncated filenames so less likely to clash
#
diff -Nur -x '*.orig' -x '*~' rhythmbox-0.12.0/plugins/ipod/rb-ipod-source.c rhythmbox-0.12.0.new/plugins/ipod/rb-ipod-source.c
--- rhythmbox-0.12.0/plugins/ipod/rb-ipod-source.c	2009-03-12 13:26:13.000000000 +1100
+++ rhythmbox-0.12.0.new/plugins/ipod/rb-ipod-source.c	2009-04-02 23:52:00.000000000 +1100
@@ -1329,15 +1329,24 @@
 	g_free (dirname);
 
 	if (strlen (result) >= IPOD_MAX_PATH_LEN) {
-		char *ext;
+		char *ext, *sf;
 
-		ext = strrchr (result, '.');
-		if (ext == NULL) {
+		/* Find filename extension */
+		for (ext = result + strlen(result) - 1; *ext != '.' && *ext != '/' && ext != result; ext--);
+
+		if (ext[0] != '.') {
+		    sf = result + IPOD_MAX_PATH_LEN - 4;
 			result [IPOD_MAX_PATH_LEN - 1] = '\0';
 		} else {
+		    sf = result + IPOD_MAX_PATH_LEN - 4 - strlen(ext);
 			memmove (&result[IPOD_MAX_PATH_LEN - strlen (ext) - 1] ,
 				 ext, strlen (ext) + 1);
 		}
+
+		/* Add suffix to reduce the chance of a name collision with truncated name */
+		sf[0] = '~';
+		sf[1] = 'A' + g_random_int_range (0, 26);
+		sf[2] = 'A' + g_random_int_range (0, 26);
 	}
 
 	tmp = g_build_filename (mount_point, result, NULL);
