mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-05 03:14:44 +00:00
Don't drop !qB extension when rename incomplete file
PR #18186. Closes #18181.
This commit is contained in:
parent
3cf0004665
commit
0ec47db9cd
@ -520,6 +520,17 @@ void TorrentImpl::setAutoManaged(const bool enable)
|
||||
m_nativeHandle.unset_flags(lt::torrent_flags::auto_managed);
|
||||
}
|
||||
|
||||
Path TorrentImpl::wantedActualPath(int index, const Path &path) const
|
||||
{
|
||||
if (m_session->isAppendExtensionEnabled()
|
||||
&& (fileSize(index) > 0) && !m_completedFiles.at(index))
|
||||
{
|
||||
return path + QB_EXT;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
QVector<TrackerEntry> TorrentImpl::trackers() const
|
||||
{
|
||||
return m_trackerEntries;
|
||||
@ -1709,15 +1720,12 @@ void TorrentImpl::moveStorage(const Path &newPath, const MoveStorageMode mode)
|
||||
|
||||
void TorrentImpl::renameFile(const int index, const Path &path)
|
||||
{
|
||||
const QVector<lt::file_index_t> nativeIndexes = m_torrentInfo.nativeIndexes();
|
||||
|
||||
Q_ASSERT(index >= 0);
|
||||
Q_ASSERT(index < nativeIndexes.size());
|
||||
if ((index < 0) || (index >= nativeIndexes.size()))
|
||||
Q_ASSERT((index >= 0) && (index < filesCount()));
|
||||
if (Q_UNLIKELY((index < 0) || (index >= filesCount())))
|
||||
return;
|
||||
|
||||
++m_renameCount;
|
||||
m_nativeHandle.rename_file(nativeIndexes[index], path.toString().toStdString());
|
||||
const Path wantedPath = wantedActualPath(index, path);
|
||||
doRenameFile(index, wantedPath);
|
||||
}
|
||||
|
||||
void TorrentImpl::handleStateUpdate(const lt::torrent_status &nativeStatus)
|
||||
@ -1969,13 +1977,12 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p)
|
||||
// For example renaming "a/b/c" to "d/b/c", then folders "a/b" and "a" will
|
||||
// be removed if they are empty
|
||||
const Path oldFilePath = m_filePaths.at(fileIndex);
|
||||
const Path newFilePath {QString::fromUtf8(p->new_name())};
|
||||
const Path newFilePath = Path(QString::fromUtf8(p->new_name())).removedExtension(QB_EXT);
|
||||
|
||||
// Check if ".!qB" extension was just added or removed
|
||||
// We should compare path in a case sensitive manner even on case insensitive
|
||||
// platforms since it can be renamed by only changing case of some character(s)
|
||||
if ((oldFilePath.data() != newFilePath.data())
|
||||
&& ((oldFilePath + QB_EXT) != newFilePath))
|
||||
if (oldFilePath.data() != newFilePath.data())
|
||||
{
|
||||
m_filePaths[fileIndex] = newFilePath;
|
||||
|
||||
@ -2027,7 +2034,7 @@ void TorrentImpl::handleFileCompletedAlert(const lt::file_completed_alert *p)
|
||||
if (actualPath != path)
|
||||
{
|
||||
qDebug("Renaming %s to %s", qUtf8Printable(actualPath.toString()), qUtf8Printable(path.toString()));
|
||||
renameFile(fileIndex, path);
|
||||
doRenameFile(fileIndex, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2134,7 +2141,6 @@ void TorrentImpl::manageIncompleteFiles()
|
||||
{
|
||||
const std::shared_ptr<const lt::torrent_info> nativeInfo = nativeTorrentInfo();
|
||||
const lt::file_storage &nativeFiles = nativeInfo->files();
|
||||
const bool isAppendExtensionEnabled = m_session->isAppendExtensionEnabled();
|
||||
|
||||
for (int i = 0; i < filesCount(); ++i)
|
||||
{
|
||||
@ -2142,23 +2148,11 @@ void TorrentImpl::manageIncompleteFiles()
|
||||
|
||||
const auto nativeIndex = m_torrentInfo.nativeIndexes().at(i);
|
||||
const Path actualPath {nativeFiles.file_path(nativeIndex)};
|
||||
|
||||
if (isAppendExtensionEnabled && (fileSize(i) > 0) && !m_completedFiles.at(i))
|
||||
{
|
||||
const Path wantedPath = path + QB_EXT;
|
||||
const Path wantedPath = wantedActualPath(i, path);
|
||||
if (actualPath != wantedPath)
|
||||
{
|
||||
qDebug() << "Renaming" << actualPath.toString() << "to" << wantedPath.toString();
|
||||
renameFile(i, wantedPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (actualPath != path)
|
||||
{
|
||||
qDebug() << "Renaming" << actualPath.toString() << "to" << path.toString();
|
||||
renameFile(i, path);
|
||||
}
|
||||
doRenameFile(i, wantedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2173,6 +2167,19 @@ void TorrentImpl::adjustStorageLocation()
|
||||
moveStorage(targetPath, MoveStorageMode::FailIfExist);
|
||||
}
|
||||
|
||||
void TorrentImpl::doRenameFile(int index, const Path &path)
|
||||
{
|
||||
const QVector<lt::file_index_t> nativeIndexes = m_torrentInfo.nativeIndexes();
|
||||
|
||||
Q_ASSERT(index >= 0);
|
||||
Q_ASSERT(index < nativeIndexes.size());
|
||||
if (Q_UNLIKELY((index < 0) || (index >= nativeIndexes.size())))
|
||||
return;
|
||||
|
||||
++m_renameCount;
|
||||
m_nativeHandle.rename_file(nativeIndexes[index], path.toString().toStdString());
|
||||
}
|
||||
|
||||
lt::torrent_handle TorrentImpl::nativeHandle() const
|
||||
{
|
||||
return m_nativeHandle;
|
||||
|
@ -279,7 +279,9 @@ namespace BitTorrent
|
||||
|
||||
void setAutoManaged(bool enable);
|
||||
|
||||
Path wantedActualPath(int index, const Path &path) const;
|
||||
void adjustStorageLocation();
|
||||
void doRenameFile(int index, const Path &path);
|
||||
void moveStorage(const Path &newPath, MoveStorageMode mode);
|
||||
void manageIncompleteFiles();
|
||||
void applyFirstLastPiecePriority(bool enabled);
|
||||
|
Loading…
x
Reference in New Issue
Block a user