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 771583 - batch rename: Fails to rename on name conflicts in the final name.
batch rename: Fails to rename on name conflicts in the final name.
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: File and Folder Operations
3.21.x
Other Linux
: Normal critical
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
: 775601 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-09-17 09:58 UTC by Mohammed Sadiq
Modified: 2017-10-28 11:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add case for files reordering in batch rename (12.42 KB, patch)
2016-09-19 14:01 UTC, Alexandru Pandelea
needs-work Details | Review
batch-rename: fix file reordering before the rename (14.82 KB, patch)
2016-10-16 17:57 UTC, Alexandru Pandelea
none Details | Review
batch-rename: fix file reordering before the rename (14.84 KB, patch)
2016-10-16 18:04 UTC, Alexandru Pandelea
none Details | Review
batch-rename: fix file reordering before the rename (14.94 KB, patch)
2016-10-26 17:28 UTC, Alexandru Pandelea
committed Details | Review

Description Mohammed Sadiq 2016-09-17 09:58:18 UTC
Batch rename fails to rename the following:

How to reproduce (Note: Files are sorted as A-Z):
1. Create some files.
   touch 0 1 2
2. Select those files -> Right click -> Rename
3. Select the template '[1, 2, 3]' -> Click Rename

Result:
2 is renamed as 3. None else is renamed.

Expected result:
The files should be renamed as per the template.

Marking as critical, because C-Z after this causes Nautilus crash, but if this is fixed, hopefully crash won't happen.
Comment 1 Carlos Soriano 2016-09-19 08:18:57 UTC
please file a new bug for the crash.
Comment 2 Alexandru Pandelea 2016-09-19 14:01:59 UTC
Created attachment 335857 [details] [review]
Add case for files reordering in batch rename

When considering if a file should be moved to the top of the list, it
is not enough to look at all files old name and at the new name of the
current file, but it is also necessary to compare the old name of the
current file with each new name of the other files.
Comment 3 Carlos Soriano 2016-10-04 19:24:11 UTC
Review of attachment 335857 [details] [review]:

Hey Alex, thanks for the patch!

In general, the code is repeated and I have the feeling this "ordering files to avoid rename conflicts" could be a standalone function in some utility file, to be used both by the redo/undo operations and batch-rename-dialog.

So let's try to do that? If you need some help figuring out a better solution, feel free to ask. But I'm pretty sure we can come with something minimal that goes well with all the cases of reordering.

::: src/nautilus-batch-rename-dialog.c
@@ +520,3 @@
+
+                break;
+                new_names = g_list_remove_link (new_names, new_names_list);

this code kinda does also what the undo/redo functions does. I believe this can be shared up to some point.

::: src/nautilus-file-undo-operations.c
@@ +1170,2 @@
             {
+                if (g_strcmp0 (file_name, new_file_name->str) == 0)

is not this function an almost copy paste of the one below? if that's the case, you can extract the common bits in a shared function.
Comment 4 Alexandru Pandelea 2016-10-16 17:57:15 UTC
Created attachment 337795 [details] [review]
batch-rename: fix file reordering before the rename

There are cases where the files are not reordered correctly.

To fix this, the order of the files is checked until no more changes
are made.

In this patch, the reordering code is also extracted in a common function.
Comment 5 Alexandru Pandelea 2016-10-16 18:04:12 UTC
Created attachment 337796 [details] [review]
batch-rename: fix file reordering before the rename

There are cases where the files are not reordered correctly.

To fix this, the order of the files is checked until no more changes
are made.

In this patch, the reordering code is also extracted in a common function.
Comment 6 Carlos Soriano 2016-10-24 20:44:21 UTC
Review of attachment 337796 [details] [review]:

This is definitely a step forward, thanks!
The code is clean, although still not very clear, but I don't have a better proposal yet :(

So this LGTM except for some nitpicks:

::: src/nautilus-batch-rename-utilities.c
@@ +145,3 @@
+                                    GList   **old_names,
+                                    GList   **new_files,
+                                    GList   **old_files,

wrong identation, one space more in the **

@@ +164,3 @@
+    GFile *old_file;
+    NautilusFile *file;
+    GList *files2;

since this is the loop's initializer, can you initialize it just before the loop instead?

@@ +169,3 @@
+     * file1 -> file2
+     * file2 -> file3
+    GList *old_files_list = NULL;

add a new line with */

::: src/nautilus-batch-rename-utilities.h
@@ +67,3 @@
+                                         GList   **old_names,
+                                         GList   **new_files,
+                                         GList   **old_files,

dito
Comment 7 Alexandru Pandelea 2016-10-26 17:28:18 UTC
Created attachment 338537 [details] [review]
batch-rename: fix file reordering before the rename

There are cases where the files are not reordered correctly.

To fix this, the order of the files is checked until no more changes
are made.

In this patch, the reordering code is also extracted in a common function.
Comment 8 Alexandru Pandelea 2016-10-26 17:30:49 UTC
Attachment 338537 [details] pushed as fc4135d - batch-rename: fix file reordering before the rename
Comment 9 Maxim Britov 2017-01-12 09:07:39 UTC
nobody test patches here?

nautilus-3.22.2:
./configure --enable-tracker=no  --disable-selinux
make
......

In file included from nautilus-file-undo-operations.c:35:0:
nautilus-batch-rename-utilities.h:24:28: fatal error: tracker-sparql.h: No such file or directory
compilation terminated.
Comment 10 Ernestas Kulik 2017-01-12 09:40:44 UTC
(In reply to ungifted from comment #9)
> nobody test patches here?
> 
> nautilus-3.22.2:
> ./configure --enable-tracker=no  --disable-selinux
> make
> ......
> 
> In file included from nautilus-file-undo-operations.c:35:0:
> nautilus-batch-rename-utilities.h:24:28: fatal error: tracker-sparql.h: No
> such file or directory
> compilation terminated.

Please refer to bug 775935.
Comment 11 Carlos Soriano 2017-01-12 12:52:40 UTC
(In reply to ungifted from comment #9)
> nobody test patches here?

no, thanks for testing :)
Comment 12 António Fernandes 2017-10-28 11:17:54 UTC
*** Bug 775601 has been marked as a duplicate of this bug. ***