From: APTX Date: Fri, 26 Apr 2013 18:27:17 +0000 (+0200) Subject: Clean up empty directories after rename. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=9065df4e5a9f09241ec185fcf437514a291dffcd;p=localmylist.git Clean up empty directories after rename. Sometimes, when data in LML changes, files might get moved from a directory created by rename rules. This might leave some empty directories. This change cleans up those directories after renaming. --- diff --git a/localmylist/renamehandler.cpp b/localmylist/renamehandler.cpp index f06b03a..8b11234 100644 --- a/localmylist/renamehandler.cpp +++ b/localmylist/renamehandler.cpp @@ -174,7 +174,18 @@ void RenameHandler::handleRename() db->log(tr("Rename: File <%1> was renamed to <%2>").arg(oldFile.canonicalFilePath()).arg(newFileString)); - // TODO cleanup empty dirs + QDir dir = oldFile.dir(); + dir.setFilter(QDir::NoDotAndDotDot | QDir::AllEntries); + while (!dir.count()) + { + if (!dir.rmdir(dir.canonicalPath())) + { + qDebug() << "Failed to remove empty directory " << dir.path(); + break; + } + if (!dir.cdUp()) + break; + } } emit renameBatchFinished();