mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Fix potential bug when moving single file torrents to tmp folder (closes #932861)
This commit is contained in:
parent
dd7e515f9c
commit
fb60a6489b
1 changed files with 16 additions and 7 deletions
|
@ -670,7 +670,9 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
bool was_seed = is_seed();
|
bool was_seed = is_seed();
|
||||||
vector<size_type> progress;
|
vector<size_type> progress;
|
||||||
file_progress(progress);
|
file_progress(progress);
|
||||||
|
qDebug() << Q_FUNC_INFO << "Changing files priorities...";
|
||||||
torrent_handle::prioritize_files(files);
|
torrent_handle::prioritize_files(files);
|
||||||
|
qDebug() << Q_FUNC_INFO << "Moving unwanted files to .unwanted folder...";
|
||||||
for(uint i=0; i<files.size(); ++i) {
|
for(uint i=0; i<files.size(); ++i) {
|
||||||
// Move unwanted files to a .unwanted subfolder
|
// Move unwanted files to a .unwanted subfolder
|
||||||
if(files[i] == 0 && progress[i] < filesize_at(i)) {
|
if(files[i] == 0 && progress[i] < filesize_at(i)) {
|
||||||
|
@ -706,19 +708,25 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Move wanted files back to their original folder
|
// Move wanted files back to their original folder
|
||||||
|
qDebug() << Q_FUNC_INFO << "Moving wanted files back from .unwanted folder";
|
||||||
if(files[i] > 0) {
|
if(files[i] > 0) {
|
||||||
QString old_path = filepath_at(i);
|
QString parent_relpath = misc::branchPath(filepath_at(i));
|
||||||
|
if(QDir(parent_relpath).dirName() == ".unwanted") {
|
||||||
QString old_name = filename_at(i);
|
QString old_name = filename_at(i);
|
||||||
QDir parent_path(misc::branchPath(old_path));
|
QString new_relpath = misc::branchPath(parent_relpath);
|
||||||
if(parent_path.dirName() == ".unwanted") {
|
if (new_relpath.isEmpty())
|
||||||
QDir new_path(misc::branchPath(parent_path.path()));
|
rename_file(i, old_name);
|
||||||
rename_file(i, new_path.filePath(old_name));
|
else
|
||||||
|
rename_file(i, QDir(new_relpath).filePath(old_name));
|
||||||
// Remove .unwanted directory if empty
|
// Remove .unwanted directory if empty
|
||||||
new_path.rmdir(".unwanted");
|
qDebug() << "Attempting to remove .unwanted folder at " << QDir(save_path() + QDir::separator() + new_relpath).absoluteFilePath(".unwanted");
|
||||||
|
QDir(save_path() + QDir::separator() + new_relpath).rmdir(".unwanted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(was_seed && !is_seed()) {
|
if(was_seed && !is_seed()) {
|
||||||
|
qDebug() << "Torrent is no longer SEEDING";
|
||||||
// Save seed status
|
// Save seed status
|
||||||
TorrentPersistentData::saveSeedStatus(*this);
|
TorrentPersistentData::saveSeedStatus(*this);
|
||||||
// Move to temp folder if necessary
|
// Move to temp folder if necessary
|
||||||
|
@ -728,6 +736,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
QString root_folder = TorrentPersistentData::getRootFolder(hash());
|
QString root_folder = TorrentPersistentData::getRootFolder(hash());
|
||||||
if(!root_folder.isEmpty())
|
if(!root_folder.isEmpty())
|
||||||
tmp_path = QDir(tmp_path).absoluteFilePath(root_folder);
|
tmp_path = QDir(tmp_path).absoluteFilePath(root_folder);
|
||||||
|
qDebug() << "tmp folder is enabled, move torrent to " << tmp_path << " from " << save_path();
|
||||||
move_storage(tmp_path);
|
move_storage(tmp_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue