[nautilus] batch-rename: Fix issue with renaming files with same name



commit ac567f53f2206a991f2428ec9e093c8bd490eabc
Author: Corey Berla <corey berla me>
Date:   Fri Jun 3 22:55:56 2022 +0000

    batch-rename: Fix issue with renaming files with same name
    
    Nautilus freezes when batch rename has files with the same name.
    An example of this issue is batch renaming from search results.
    This issue is caused because batch_rename_sort_lists_for_rename()
    gets stuck in a infinite loop trying to sort files with the same name.
    Updated the function batch_rename_sort_lists_for_rename()
    to only change order if the files have the same parent.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2144

 src/nautilus-batch-rename-utilities.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-batch-rename-utilities.c b/src/nautilus-batch-rename-utilities.c
index 49b9813ed..a81fc2ea7 100644
--- a/src/nautilus-batch-rename-utilities.c
+++ b/src/nautilus-batch-rename-utilities.c
@@ -189,9 +189,11 @@ batch_rename_sort_lists_for_rename (GList    **selection,
              new_names_list = new_names_list->next, files = files->next)
         {
             g_autofree gchar *old_file_name = NULL;
+            g_autoptr (NautilusFile) parent = NULL;
 
             old_file_name = nautilus_file_get_name (NAUTILUS_FILE (files->data));
             new_file_name = new_names_list->data;
+            parent = nautilus_file_get_parent (NAUTILUS_FILE (files->data));
 
             if (is_undo_redo)
             {
@@ -205,11 +207,15 @@ batch_rename_sort_lists_for_rename (GList    **selection,
                  files2 = files2->next, new_names_list2 = new_names_list2->next)
             {
                 g_autofree gchar *file_name = NULL;
+                g_autoptr (NautilusFile) parent2 = NULL;
 
                 file_name = nautilus_file_get_name (NAUTILUS_FILE (files2->data));
                 new_name = new_names_list2->data;
 
-                if (files2 != files && g_strcmp0 (file_name, new_file_name->str) == 0)
+                parent2 = nautilus_file_get_parent (NAUTILUS_FILE (files2->data));
+
+                if (files2 != files && g_strcmp0 (file_name, new_file_name->str) == 0 &&
+                    parent == parent2)
                 {
                     file = NAUTILUS_FILE (files2->data);
 


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