Browse Source

Merge pull request #12994 from glassez/custom-storage

Find complete files when moving torrent storage
adaptive-webui-19844
Vladimir Golovnev 4 years ago committed by GitHub
parent
commit
9dfeeb9e81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 53
      src/base/bittorrent/customstorage.cpp
  2. 2
      src/base/bittorrent/customstorage.h

53
src/base/bittorrent/customstorage.cpp

@ -49,7 +49,33 @@ CustomStorage::CustomStorage(const lt::storage_params &params, lt::file_pool &fi @@ -49,7 +49,33 @@ CustomStorage::CustomStorage(const lt::storage_params &params, lt::file_pool &fi
bool CustomStorage::verify_resume_data(const lt::add_torrent_params &rd, const lt::aux::vector<std::string, lt::file_index_t> &links, lt::storage_error &ec)
{
const QDir saveDir {m_savePath};
handleCompleteFiles(m_savePath);
return lt::default_storage::verify_resume_data(rd, links, ec);
}
void CustomStorage::set_file_priority(lt::aux::vector<lt::download_priority_t, lt::file_index_t> &priorities, lt::storage_error &ec)
{
m_filePriorities = priorities;
lt::default_storage::set_file_priority(priorities, ec);
}
lt::status_t CustomStorage::move_storage(const std::string &savePath, lt::move_flags_t flags, lt::storage_error &ec)
{
const QString newSavePath {Utils::Fs::expandPathAbs(QString::fromStdString(savePath))};
if (flags == lt::move_flags_t::dont_replace)
handleCompleteFiles(newSavePath);
const lt::status_t ret = lt::default_storage::move_storage(savePath, flags, ec);
if (ret != lt::status_t::fatal_disk_error)
m_savePath = newSavePath;
return ret;
}
void CustomStorage::handleCompleteFiles(const QString &savePath)
{
const QDir saveDir {savePath};
const lt::file_storage &fileStorage = files();
for (const lt::file_index_t fileIndex : fileStorage.file_range()) {
@ -65,29 +91,12 @@ bool CustomStorage::verify_resume_data(const lt::add_torrent_params &rd, const l @@ -65,29 +91,12 @@ bool CustomStorage::verify_resume_data(const lt::add_torrent_params &rd, const l
const QString completeFilePath = filePath.left(filePath.size() - QB_EXT.size());
QFile completeFile {saveDir.absoluteFilePath(completeFilePath)};
if (completeFile.exists()) {
QFile currentFile {saveDir.absoluteFilePath(filePath)};
if (currentFile.exists())
currentFile.remove();
completeFile.rename(currentFile.fileName());
QFile incompleteFile {saveDir.absoluteFilePath(filePath)};
if (incompleteFile.exists())
incompleteFile.remove();
completeFile.rename(incompleteFile.fileName());
}
}
}
return lt::default_storage::verify_resume_data(rd, links, ec);
}
void CustomStorage::set_file_priority(lt::aux::vector<lt::download_priority_t, lt::file_index_t> &priorities, lt::storage_error &ec)
{
m_filePriorities = priorities;
lt::default_storage::set_file_priority(priorities, ec);
}
lt::status_t CustomStorage::move_storage(const std::string &savePath, lt::move_flags_t flags, lt::storage_error &ec)
{
const lt::status_t ret = lt::default_storage::move_storage(savePath, flags, ec);
if (ret != lt::status_t::fatal_disk_error)
m_savePath = Utils::Fs::expandPathAbs(QString::fromStdString(savePath));
return ret;
}
#endif

2
src/base/bittorrent/customstorage.h

@ -49,6 +49,8 @@ public: @@ -49,6 +49,8 @@ public:
lt::status_t move_storage(const std::string &savePath, lt::move_flags_t flags, lt::storage_error &ec) override;
private:
void handleCompleteFiles(const QString &savePath);
lt::aux::vector<lt::download_priority_t, lt::file_index_t> m_filePriorities;
QString m_savePath;
};

Loading…
Cancel
Save