Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some file renaming woes (probably) #20128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/base/bittorrent/abstractfilestorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ void BitTorrent::AbstractFileStorage::renameFile(const Path &oldPath, const Path
throw RuntimeError(tr("The new path is invalid: '%1'.").arg(newPath.toString()));
if (newPath.isAbsolute())
throw RuntimeError(tr("Absolute path isn't allowed: '%1'.").arg(newPath.toString()));

if (newPath.exists())
throw RuntimeError(tr("Another file exists at new path: '%1'.").arg(newPath.toString()));

int renamingFileIndex = -1;
for (int i = 0; i < filesCount(); ++i)
{
Expand All @@ -53,7 +55,7 @@ void BitTorrent::AbstractFileStorage::renameFile(const Path &oldPath, const Path
if ((renamingFileIndex < 0) && (path == oldPath))
renamingFileIndex = i;
else if (path == newPath)
throw RuntimeError(tr("The file already exists: '%1'.").arg(newPath.toString()));
throw RuntimeError(tr("The file already exists in this torrent: '%1'.").arg(newPath.toString()));
}

if (renamingFileIndex < 0)
Expand All @@ -70,6 +72,7 @@ void BitTorrent::AbstractFileStorage::renameFolder(const Path &oldFolderPath, co
throw RuntimeError(tr("The new path is invalid: '%1'.").arg(newFolderPath.toString()));
if (newFolderPath.isAbsolute())
throw RuntimeError(tr("Absolute path isn't allowed: '%1'.").arg(newFolderPath.toString()));


QVector<int> renamingFileIndexes;
renamingFileIndexes.reserve(filesCount());
Expand All @@ -81,7 +84,7 @@ void BitTorrent::AbstractFileStorage::renameFolder(const Path &oldFolderPath, co
if (path.hasAncestor(oldFolderPath))
renamingFileIndexes.append(i);
else if (path.hasAncestor(newFolderPath))
throw RuntimeError(tr("The folder already exists: '%1'.").arg(newFolderPath.toString()));
throw RuntimeError(tr("The folder already exists in this torrent: '%1'.").arg(newFolderPath.toString()));
}

if (renamingFileIndexes.isEmpty())
Expand All @@ -90,6 +93,6 @@ void BitTorrent::AbstractFileStorage::renameFolder(const Path &oldFolderPath, co
for (const int index : renamingFileIndexes)
{
const Path newFilePath = newFolderPath / oldFolderPath.relativePathOf(filePath(index));
renameFile(index, newFilePath);
renameFile(index, newFilePath); // note; if file would be overwritten, we note that is true here
}
}
2 changes: 1 addition & 1 deletion src/base/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool Path::isRelative() const

bool Path::exists() const
{
return !isEmpty() && QFileInfo::exists(m_pathStr);
return !isValid() && QFileInfo::exists(m_pathStr);
}

Path Path::rootItem() const
Expand Down