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

Closed
wants to merge 3 commits into from

Conversation

calumapplepie
Copy link

Hullo, new contributer, wanted to avoid others losing data the way I just did!

I added a few new checks that, to my knowlege, will prevent users from renaming files on top of files that exist. While this can be useful for reseeding, it causes instant data loss if qbittorrent has downloaded any part of the existing file.

I also do some cleanup on messages and exists() function.

Reject the PR if you'd prefer to move the functionality to a different place, but I had the itch to hack something up to fix this, and I couldn't resist.

Probably closes a few issues, but I wasn't sure which, and I should get back to final projects.

@luzpaz
Copy link
Contributor

luzpaz commented Dec 16, 2023

Thanks! Can you look at https://github.com/qbittorrent/qBittorrent/issues?q=is%3Aopen+is%3Aissue+label%3A%22Data+loss%22 and see which tickets this PR addresses ?

Copy link

This PR is stale because it has been 60 days with no activity. This PR will be automatically closed within 7 days if there is no further activity.

@github-actions github-actions bot added the Stale label Feb 15, 2024
@calumapplepie
Copy link
Author

Not stale, I just don’t have the bandwidth to hunt through issues in an unfamiliar repo.

@github-actions github-actions bot removed the Stale label Feb 16, 2024
Copy link

This PR is stale because it has been 60 days with no activity. This PR will be automatically closed within 7 days if there is no further activity.

@github-actions github-actions bot added the Stale label Apr 16, 2024
@calumapplepie
Copy link
Author

calumapplepie commented Apr 16, 2024 via email

@xavier2k6 xavier2k6 requested a review from a team April 20, 2024 09:24
Copy link

This PR is stale because it has been 60 days with no activity. This PR will be automatically closed within 7 days if there is no further activity.

@github-actions github-actions bot added the Stale label Jun 20, 2024
@calumapplepie
Copy link
Author

Still not stale <3

@@ -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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is more confusing. There is no indication of what torrent it is referring to.

@@ -130,7 +130,7 @@ bool Path::isRelative() const

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

@Chocobo1 Chocobo1 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is excessive. Please revert it.

@@ -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()));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't make unrelated changes.

Suggested change

@@ -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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is more confusing. There is no indication of what torrent it is referring to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw RuntimeError(tr("The folder already exists in this torrent: '%1'.").arg(newFolderPath.toString()));
throw RuntimeError(tr("The folder path is the same: '%1'.").arg(newFolderPath.toString()));

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment audience is unclear and doesn't bear any context for the developer. Just don't add it.

Suggested change
renameFile(index, newFilePath); // note; if file would be overwritten, we note that is true here
renameFile(index, newFilePath);

@@ -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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

Suggested change
throw RuntimeError(tr("The file already exists in this torrent: '%1'.").arg(newPath.toString()));
throw RuntimeError(tr("The file path is the same: '%1'.").arg(newPath.toString()));

@github-actions github-actions bot removed the Stale label Jun 21, 2024
Copy link

This PR is stale because it has been 60 days with no activity. This PR will be automatically closed within 7 days if there is no further activity.

@github-actions github-actions bot added the Stale label Aug 20, 2024
Copy link

This PR was closed because it has been stalled for some time with no activity.

@github-actions github-actions bot closed this Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants