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