BUGFIX: Improve folder removal behavior

This commit is contained in:
Christophe Dumez
2011-03-10 19:08:33 +00:00
parent 92c70bc878
commit 01fcf82b0c
4 changed files with 22 additions and 10 deletions

View File

@@ -2,6 +2,7 @@
- BUFIX: Fix compilation with libtorrent v0.14.x
- BUGFIX: Fix issues when writing on NTFS (Linux, Mac)
- BUGFIX: Fix root folder being cut off if the torrent comes from a scanned folder (Christian Kandeler)
- BUGFIX: Improve folder removal behavior
* Sat Feb 26 2011 - Christophe Dumez <chris@qbittorrent.org> - v2.6.7
- BUGFIX: Encoding fixes (Windows)

View File

@@ -799,3 +799,13 @@ QString misc::fileName(QString file_path)
return file_path;
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;
}

View File

@@ -123,6 +123,8 @@ public:
return MyFile.remove();
}
static bool removeEmptyFolder(const QString &dirpath);
static quint64 computePathSize(QString path);
static QString truncateRootFolder(boost::intrusive_ptr<libtorrent::torrent_info> t);

View File

@@ -2118,22 +2118,21 @@ void QBtSession::readAlerts() {
#endif
if(!hash.isEmpty()) {
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 {
// XXX: Fallback
QStringList hashes_deleted;
// Fallback
qDebug() << "hash is empty, use fallback to remove save path";
foreach(const QString& key, savePathsToRemove.keys()) {
// Attempt to delete
QDir().rmpath(savePathsToRemove[key]);
if(!QDir(savePathsToRemove[key]).exists()) {
hashes_deleted << key;
if(misc::removeEmptyFolder(savePathsToRemove[key])) {
savePathsToRemove.remove(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())) {