mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
Use 'fail if exist' strategy on automatic move
Prevent existing files overwriting when torrent is moved automatically (e.g. when moved from incomplete to final save path). PR #17855.
This commit is contained in:
parent
f66ec4430d
commit
4f0990dc29
3 changed files with 18 additions and 4 deletions
|
@ -298,6 +298,21 @@ namespace
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
constexpr lt::move_flags_t toNative(const MoveStorageMode mode)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
case MoveStorageMode::FailIfExist:
|
||||||
|
return lt::move_flags_t::fail_if_exist;
|
||||||
|
case MoveStorageMode::KeepExistingFiles:
|
||||||
|
return lt::move_flags_t::dont_replace;
|
||||||
|
case MoveStorageMode::Overwrite:
|
||||||
|
return lt::move_flags_t::always_replace_files;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BitTorrent::SessionImpl::ResumeSessionContext final : public QObject
|
struct BitTorrent::SessionImpl::ResumeSessionContext final : public QObject
|
||||||
|
@ -4690,9 +4705,7 @@ void SessionImpl::moveTorrentStorage(const MoveStorageJob &job) const
|
||||||
const QString torrentName = (torrent ? torrent->name() : id.toString());
|
const QString torrentName = (torrent ? torrent->name() : id.toString());
|
||||||
LogMsg(tr("Start moving torrent. Torrent: \"%1\". Destination: \"%2\"").arg(torrentName, job.path.toString()));
|
LogMsg(tr("Start moving torrent. Torrent: \"%1\". Destination: \"%2\"").arg(torrentName, job.path.toString()));
|
||||||
|
|
||||||
job.torrentHandle.move_storage(job.path.toString().toStdString()
|
job.torrentHandle.move_storage(job.path.toString().toStdString(), toNative(job.mode));
|
||||||
, ((job.mode == MoveStorageMode::Overwrite)
|
|
||||||
? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionImpl::handleMoveTorrentStorageJobFinished(const Path &newPath)
|
void SessionImpl::handleMoveTorrentStorageJobFinished(const Path &newPath)
|
||||||
|
|
|
@ -2166,7 +2166,7 @@ void TorrentImpl::adjustStorageLocation()
|
||||||
const Path targetPath = ((isFinished || downloadPath.isEmpty()) ? savePath() : downloadPath);
|
const Path targetPath = ((isFinished || downloadPath.isEmpty()) ? savePath() : downloadPath);
|
||||||
|
|
||||||
if ((targetPath != actualStorageLocation()) || isMoveInProgress())
|
if ((targetPath != actualStorageLocation()) || isMoveInProgress())
|
||||||
moveStorage(targetPath, MoveStorageMode::Overwrite);
|
moveStorage(targetPath, MoveStorageMode::FailIfExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
lt::torrent_handle TorrentImpl::nativeHandle() const
|
lt::torrent_handle TorrentImpl::nativeHandle() const
|
||||||
|
|
|
@ -63,6 +63,7 @@ namespace BitTorrent
|
||||||
|
|
||||||
enum class MoveStorageMode
|
enum class MoveStorageMode
|
||||||
{
|
{
|
||||||
|
FailIfExist,
|
||||||
KeepExistingFiles,
|
KeepExistingFiles,
|
||||||
Overwrite
|
Overwrite
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue