leo-arch / clifm

The shell-like, command line terminal file manager: simple, fast, extensible, and lightweight as hell.
https://github.com/leo-arch/clifm/wiki
GNU General Public License v2.0
1.29k stars 41 forks source link

files getting deleted by ungood bulk rename #288

Closed muellerto closed 1 month ago

muellerto commented 2 months ago

Describe the bug When a bulk rename leads to equal file names which have been different before only one file remains.

To Reproduce I had files in a directory like these ones:

Diabolica (Hampshire Jam 27/10/01).mp3
Crete - Tea And Biscuits - Pipe (Hampshire Jam 27/10/01).mp3
Guitar Interlude - Let Me Hear You Say Yeah (Hampshire Jam 27/10/01).mp3
Roxette Lost In Liphook (Hampshire Jam 27/10/01).mp3
Diabolica (Greenhouse 23/10/01).mp3
Roxette (Greenhouse 23/10/01).mp3
Tea And Biscuits (Greenhouse 23/10/01).mp3
Pipe (Greenhouse 23/10/01).mp3
Where's Your Atom Bomb (Greenhouse 24/10/01).mp3
Crete - Tea And Sandwiches - Pipe (Greenhouse 24/10/01).mp3
An Ear For An Ending (Greenhouse 24/10/01).mp3
Tea And Cake - A Saucerful Of Biscuits - Pipe (Greenhouse 25/10/01).mp3
An Eye For An Ending (Greenhouse 25/10/01).mp3
Diabolica (For Wayne And Evil Dave) (Greenhouse 25/10/01).mp3

(Yes, real file names with brackets and slashes, don't ask ...)

Then I did br * on them and let vi remove the brackets stuff:

1,$s/ (.\+)//g

This was not a good idea because the three Diabolica files get indeed the same resulting name:

Diabolica.mp3
Crete - Tea And Biscuits - Pipe.mp3
Guitar Interlude - Let Me Hear You Say Yeah.mp3
Roxette Lost In Liphook.mp3
Diabolica.mp3
Roxette.mp3
Tea And Biscuits.mp3
Pipe.mp3
Where's Your Atom Bomb.mp3
Crete - Tea And Sandwiches - Pipe.mp3
An Ear For An Ending.mp3
Tea And Cake - A Saucerful Of Biscuits - Pipe.mp3
An Eye For An Ending.mp3
Diabolica.mp3

But I didn't pay enough attention and so I did it. In the result of the bulk rename operation you have not 14 but only 12 files, two are missing. I think this is done just by mv, and mv just does it this way. Yes, I read

This built-in bulk rename function won't deal with deletions, replacements, file name conflicts and the like. For a smarter alternative use qmv(1).

But two things are really not good here:

  1. it happens without any warning before, you also don't get an error message later, you don't even notice it
  2. you don't know what files have been deleted and which one survived

Look, clifm transcends mv here a lot: a real bulk rename operation is not a concept of mv. So clifm should take it's responsibility here serious. When you bulk rename a bunch of hundred files you can easily make a mistake, especially when you use automated vi commands like I did. And a check would be rather simple (OK, I speak always in C++ terms with sorted containers and all that ...)

Expected behavior I think bulk rename should detect that two (or more) files will get the same name before the operation is started because this is probably always not intended by the user. Perhaps it would also be a good feature to see what happens, an output like

oldfile1 -> newfile1
oldfile2 -> newfile2
oldfile3 -> newfile3

Desktop:

leo-arch commented 2 months ago

Thanks for reporting @muellerto! I'll take a look at it as soon as I can.

leo-arch commented 1 month ago

Ok. The bulk rename function now checks for duplicate/existing files before renaming, warns and prompts the user for confirmation. Give it a try and let me know how it works.

muellerto commented 1 month ago

Yeah, great, even on Windows with case insensitive file names. Thanks a lot!