Verified Commit 276d30f2 authored by Callum Parsey's avatar Callum Parsey
Browse files

filerenamer: Prevent creating track name folders

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.
parent 107c59c6
......@@ -916,7 +916,7 @@ bool FileRenamer::moveFile(const QString &src, const QString &dest)
if(!srcURL.isValid() || !dstURL.isValid() || srcURL == dstURL)
return false;
QUrl dir = dstURL.resolved(QUrl::fromUserInput(".")); // resolves to path w/out filename
QUrl dir = dstURL.adjusted(QUrl::RemoveFilename); // resolves to path w/out filename
if(!QDir().mkpath(dir.path())) {
qCCritical(JUK_LOG) << "Unable to create directory " << dir.path();
return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment