Re: [Easytag-mailing] EasyTAG-<2.x>-<renaming 2 files to the same name deletes 1 file>



Here is a patch to fix the problem....

Jerome


peter bergt wrote, the 09.06.2007 12:09 :
Hi,

it is really strange; as mentioned most time files aren't overwritten
but I've found a new combination to loose files

file1: "AcDc - Thunderstruck.mp3"
file2: "ACDC - Thunderstruck.mp3"

rename file1 to the name of the 2nd file and the result is one file left
and one missing - has it something to to with capitals?

but eg: renaming file1 and file2 to "aaBB ccDD.mp3" gives a warning on
the 2nd file that the file exists and it can't be renamed

cu
peter

peter bergt wrote:
Hello!

I'm using version 2.0; I just compiled 2.1 and got the same result as in
version 2.0 so I guess both versions are affected

at least I can reproduce it
usually if you rename 2 mp3 files to the same name you get a warning and
nothing bad happens to the 2 files

but not in this case:

file1: "112kb Men at Work - Who Can It Be Now.mp3"
file2: "Men at Work - Who Can It Be Now.mp3"

change both to "Men at Work - Who Can It be Now.mp3"
(note: "be" instead of Be so that both files have to be renamed)

when I press the safe button both files are renamed to
"Men at Work - Who Can It be Now.mp3" and the result is that
one file is missing ... (easytag still shows 2 files with the same name,
different tags are still present as long as the dir is not refreshed)

if I use other filenames etc I get a warning but not in this case
I've tested it with different mp3 files and gave them the above names
the result is always one file missing

any ideas what I did wrong - or is it a strange bug?

cu
peter



--
EasyTAG - Tag editor for MP3 and Ogg Vorbis files
http://easytag.sourceforge.net
--
Jerome COUDERC <easytag gmail com>

diff -ruN easytag-2.1.orig/src/easytag.c easytag-2.1/src/easytag.c
--- easytag-2.1.orig/src/easytag.c	2007-05-01 01:06:23.000000000 +0200
+++ easytag-2.1/src/easytag.c	2007-06-19 00:21:57.000000000 +0200
@@ -2699,36 +2699,6 @@
     Statusbar_Message(msg,TRUE);
     g_free(msg);
 
-    /* Check if a file already exists with the new name, and detect if
-     * it's only a case change (needs for vfat) */
-    if ( (file=fopen(new_filename,"r"))!=NULL )
-    {
-        gchar *cur_filename_folded = g_utf8_casefold(cur_filename_utf8, -1);
-        gchar *new_filename_folded = g_utf8_casefold(new_filename_utf8, -1);
-        gchar *msg;
-        GtkWidget *msgbox;
-
-        fclose(file);
-        if ( g_utf8_collate(cur_filename_folded,new_filename_folded) != 0 ) // Case was folded before!
-        {
-            msg = g_strdup_printf(_("Can't rename file \n'%s'\nbecause the following "
-                        "file already exists:\n'%s'"),cur_basename_utf8,new_basename_utf8);
-            msgbox = msg_box_new(_("Error..."),msg,GTK_STOCK_DIALOG_ERROR,BUTTON_OK,0);
-            g_free(msg);
-            msg_box_hide_check_button(MSG_BOX(msgbox));
-            msg_box_run(MSG_BOX(msgbox));
-            gtk_widget_destroy(msgbox);
-
-            Statusbar_Message(_("File(s) not renamed..."),TRUE);
-
-            g_free(new_basename_utf8);
-            g_free(cur_basename_utf8);
-            g_free(cur_filename_folded);
-            g_free(new_filename_folded);
-            return;
-        }
-    }
-
     /* We use two stages to rename file, to avoid problem with some system
      * that doesn't allow to rename the file if only the case has changed. */
     tmp_filename = g_strdup_printf("%s.XXXXXX",cur_filename);
@@ -2738,6 +2708,7 @@
         unlink(tmp_filename);
     }
 
+    // Rename to the temporary name
     if ( rename(cur_filename,tmp_filename)!=0 ) // => rename() fails
     {
         gchar *msg;
@@ -2759,6 +2730,54 @@
         return;
     }
 
+    /* Check if the new file name already exists. Must be done after changing 
+     * filename to the temporary name, else we can't detect the problem under 
+     * Linux when renaming a file 'aa.mp3' to 'AA.mp3' and if the last one 
+     * already exists */
+    if ( (file=fopen(new_filename,"r"))!=NULL )
+    {
+        GtkWidget *msgbox;
+
+        fclose(file);
+
+        // Restore the initial name
+        if ( rename(tmp_filename,cur_filename)!=0 ) // => rename() fails
+        {
+            gchar *msg;
+            GtkWidget *msgbox;
+
+            /* Renaming file from the temporary filename has failed */
+            msg = g_strdup_printf(_("Can't rename file '%s'\n to \n'%s'!\n(%s)"),
+                                    new_basename_utf8,cur_basename_utf8,g_strerror(errno));
+            msgbox = msg_box_new(_("Error..."),msg,GTK_STOCK_DIALOG_ERROR,BUTTON_OK,0);
+            g_free(msg);
+            msg_box_hide_check_button(MSG_BOX(msgbox));
+            msg_box_run(MSG_BOX(msgbox));
+            gtk_widget_destroy(msgbox);
+
+            Statusbar_Message(_("File(s) not renamed..."),TRUE);
+            g_free(tmp_filename);
+            g_free(cur_basename_utf8);
+            g_free(new_basename_utf8);
+            return;
+        }
+
+        msg = g_strdup_printf(_("Can't rename file \n'%s'\nbecause the following "
+                    "file already exists:\n'%s'"),cur_basename_utf8,new_basename_utf8);
+        msgbox = msg_box_new(_("Error..."),msg,GTK_STOCK_DIALOG_ERROR,BUTTON_OK,0);
+        g_free(msg);
+        msg_box_hide_check_button(MSG_BOX(msgbox));
+        msg_box_run(MSG_BOX(msgbox));
+        gtk_widget_destroy(msgbox);
+
+        Statusbar_Message(_("File(s) not renamed..."),TRUE);
+
+        g_free(new_basename_utf8);
+        g_free(cur_basename_utf8);
+        return;
+
+    }
+
     /* If files are in different directories, we need to create the new
      * destination directory */
     dirname_cur = g_path_get_dirname(tmp_filename);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]