Skip to content

filerenamer: Prevent creating track name folders

Callum Parsey requested to merge (removed):fix-rename-folders into master

When renaming/moving tracks using the "file renamer" utility, a directory with the name of the file to be moved is created in the destination, which causes a later move of the file to fail.

As an example, let's say the renamer is set to move the file to the directory ~/Music/Artist/Album/Track.mp3. We now have a file called ~/Music/staging/Awesome.mp3 by "Johnny" from the album "Extension". Telling JuK to rename this file will result in the creation of the directories ~/Music/Johnny/, ~/Music/Johnny/Extension/ and ~/Music/Johnny/Extension/Awesome.mp3/. The creation of that last directory means that moving the real Awesome.mp3 to ~/Music/Johnny/Extension/ will fail, as a directory already exists with it's name. A generic error will appear saying that the rename failed.

A line in FileRenamer::moveFile already exists which aims to prevent this, and it may have worked in the past, but it doesn't seem to anymore. The resulting dir variable retains the name of the file even after the .resolved() call, which of course results in the extra directory being created.

To fix this, I replaced the call to .resolved() with one to .adjusted() which is supposed to guarantee that a file name is not part of the new generated URL. This should prevent any extra directories from being created, as the name of the file (or anything after the final forward slash in the destination path) is now stripped.

Another thing that could possibly be done is to keep the call to .resolved() but replace the relative path with .. instead of . as this would likely have the same effect. I chose to use .adjusted() as this seems like the cleaner and more readable solution, at least according to Qt documentation.

Merge request reports

Loading