mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 13:28:50 +03:00
Better fix for FS changes on torrent labeling
This commit is contained in:
parent
4f87819abf
commit
1052cd019b
3 changed files with 39 additions and 34 deletions
|
@ -1637,49 +1637,28 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle h, QString old_label, QString new_label) {
|
||||
if(!h.is_valid()) return;
|
||||
if(!appendLabelToSavePath) return;
|
||||
if(old_label == new_label) return;
|
||||
QString old_save_path = TorrentPersistentData::getSavePath(h.hash());
|
||||
if(!old_save_path.startsWith(defaultSavePath)) return;
|
||||
QString new_save_path = old_save_path.replace(defaultSavePath, "");
|
||||
QStringList path_parts = new_save_path.split(QDir::separator(), QString::SkipEmptyParts);
|
||||
if(path_parts.empty()) {
|
||||
if(!new_label.isEmpty())
|
||||
path_parts << new_label;
|
||||
} else {
|
||||
if(old_label.isEmpty() || path_parts.first() != old_label) {
|
||||
path_parts.prepend(new_label);
|
||||
} else {
|
||||
if(new_label.isEmpty())
|
||||
path_parts.removeAt(0);
|
||||
else
|
||||
path_parts.replace(0, new_label);
|
||||
}
|
||||
}
|
||||
new_save_path = defaultSavePath;
|
||||
if(!new_save_path.endsWith(QDir::separator())) new_save_path += QDir::separator();
|
||||
new_save_path += path_parts.join(QDir::separator());
|
||||
TorrentPersistentData::saveSavePath(h.hash(), new_save_path);
|
||||
QString new_save_path = misc::updateLabelInSavePath(defaultSavePath, old_save_path, old_label, new_label);
|
||||
if(new_save_path != old_save_path) {
|
||||
// Move storage
|
||||
qDebug("Moving storage to %s", qPrintable(new_save_path));
|
||||
QDir().mkpath(new_save_path);
|
||||
h.move_storage(new_save_path);
|
||||
emit savePathChanged(h);
|
||||
}
|
||||
}
|
||||
|
||||
void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) {
|
||||
if(!h.is_valid()) return;
|
||||
const QString &label = TorrentPersistentData::getLabel(h.hash());
|
||||
if(label.isEmpty()) return;
|
||||
// Current save path
|
||||
const QString &old_save_path = TorrentPersistentData::getSavePath(h.hash());
|
||||
const QDir old_dir(old_save_path);
|
||||
if(old_dir.dirName() != label) {
|
||||
const QString &new_save_path = old_dir.absoluteFilePath(label);
|
||||
TorrentPersistentData::saveSavePath(h.hash(), new_save_path);
|
||||
if(old_dir == QDir(h.save_path())) {
|
||||
QString old_save_path = TorrentPersistentData::getSavePath(h.hash());
|
||||
QString new_save_path = misc::updateLabelInSavePath(defaultSavePath, old_save_path, "", label);
|
||||
if(old_save_path != new_save_path) {
|
||||
// Move storage
|
||||
h.move_storage(new_save_path);
|
||||
}
|
||||
emit savePathChanged(h);
|
||||
}
|
||||
}
|
||||
|
@ -2198,7 +2177,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||
if(savePath.isEmpty()) {
|
||||
savePath = defaultSavePath;
|
||||
}
|
||||
if(appendLabelToSavePath) {
|
||||
if(appendLabelToSavePath && savePath.startsWith(defaultSavePath)) {
|
||||
qDebug("appendLabelToSavePath is true");
|
||||
const QString &label = TorrentTempData::getLabel(hash);
|
||||
if(!label.isEmpty()) {
|
||||
|
|
24
src/misc.cpp
24
src/misc.cpp
|
@ -248,6 +248,30 @@ void misc::copyDir(QString src_path, QString dst_path) {
|
|||
}
|
||||
}
|
||||
|
||||
QString misc::updateLabelInSavePath(const QString& defaultSavePath, QString save_path, const QString old_label, const QString new_label) {
|
||||
if(old_label == new_label) return save_path;
|
||||
if(!save_path.startsWith(defaultSavePath)) return save_path;
|
||||
QString new_save_path = save_path.replace(defaultSavePath, "");
|
||||
QStringList path_parts = new_save_path.split(QDir::separator(), QString::SkipEmptyParts);
|
||||
if(path_parts.empty()) {
|
||||
if(!new_label.isEmpty())
|
||||
path_parts << new_label;
|
||||
} else {
|
||||
if(old_label.isEmpty() || path_parts.first() != old_label) {
|
||||
path_parts.prepend(new_label);
|
||||
} else {
|
||||
if(new_label.isEmpty())
|
||||
path_parts.removeAt(0);
|
||||
else
|
||||
path_parts.replace(0, new_label);
|
||||
}
|
||||
}
|
||||
new_save_path = defaultSavePath;
|
||||
if(!new_save_path.endsWith(QDir::separator())) new_save_path += QDir::separator();
|
||||
new_save_path += path_parts.join(QDir::separator());
|
||||
return new_save_path;
|
||||
}
|
||||
|
||||
void misc::moveToXDGFolders() {
|
||||
const QString &old_qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();
|
||||
if(QDir(old_qBtPath).exists()) {
|
||||
|
|
|
@ -73,6 +73,8 @@ public:
|
|||
static QString truncateRootFolder(boost::intrusive_ptr<torrent_info> t);
|
||||
static QString truncateRootFolder(torrent_handle h);
|
||||
|
||||
static QString updateLabelInSavePath(const QString& defaultSavePath, QString save_path, const QString old_label, const QString new_label);
|
||||
|
||||
static bool sameFiles(QString path1, QString path2);
|
||||
static void copyDir(QString src_path, QString dst_path);
|
||||
// Introduced in v2.1.0 for backward compatibility
|
||||
|
|
Loading…
Reference in a new issue