mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-12 16:23:07 -07:00
Improve folder removal behavior
This commit is contained in:
parent
feeecbf395
commit
15d3b07f34
3 changed files with 21 additions and 10 deletions
10
src/misc.cpp
10
src/misc.cpp
|
@ -799,3 +799,13 @@ QString misc::fileName(QString file_path)
|
||||||
return file_path;
|
return file_path;
|
||||||
return file_path.mid(slash_index+1);
|
return file_path.mid(slash_index+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool misc::removeEmptyFolder(const QString &dirpath)
|
||||||
|
{
|
||||||
|
QDir savedir(dirpath);
|
||||||
|
const QString dirname = savedir.dirName();
|
||||||
|
if(savedir.exists() && savedir.cdUp()) {
|
||||||
|
return savedir.rmdir(dirname);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -123,6 +123,8 @@ public:
|
||||||
return MyFile.remove();
|
return MyFile.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool removeEmptyFolder(const QString &dirpath);
|
||||||
|
|
||||||
static quint64 computePathSize(QString path);
|
static quint64 computePathSize(QString path);
|
||||||
|
|
||||||
static QString truncateRootFolder(boost::intrusive_ptr<libtorrent::torrent_info> t);
|
static QString truncateRootFolder(boost::intrusive_ptr<libtorrent::torrent_info> t);
|
||||||
|
|
|
@ -2176,22 +2176,21 @@ void QBtSession::readAlerts() {
|
||||||
#endif
|
#endif
|
||||||
if(!hash.isEmpty()) {
|
if(!hash.isEmpty()) {
|
||||||
if(savePathsToRemove.contains(hash)) {
|
if(savePathsToRemove.contains(hash)) {
|
||||||
QDir().rmpath(savePathsToRemove.take(hash));
|
const QString dirpath = savePathsToRemove.take(hash);
|
||||||
|
qDebug() << "Removing save path: " << dirpath << "...";
|
||||||
|
bool ok = misc::removeEmptyFolder(dirpath);
|
||||||
|
Q_UNUSED(ok);
|
||||||
|
qDebug() << "Folder was removed: " << ok;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// XXX: Fallback
|
// Fallback
|
||||||
QStringList hashes_deleted;
|
qDebug() << "hash is empty, use fallback to remove save path";
|
||||||
foreach(const QString& key, savePathsToRemove.keys()) {
|
foreach(const QString& key, savePathsToRemove.keys()) {
|
||||||
// Attempt to delete
|
// Attempt to delete
|
||||||
QDir().rmpath(savePathsToRemove[key]);
|
if(misc::removeEmptyFolder(savePathsToRemove[key])) {
|
||||||
if(!QDir(savePathsToRemove[key]).exists()) {
|
savePathsToRemove.remove(key);
|
||||||
hashes_deleted << key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Clean up
|
|
||||||
foreach(const QString& key, hashes_deleted) {
|
|
||||||
savePathsToRemove.remove(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (storage_moved_alert* p = dynamic_cast<storage_moved_alert*>(a.get())) {
|
else if (storage_moved_alert* p = dynamic_cast<storage_moved_alert*>(a.get())) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue