]> Some of my projects - localmylist.git/commitdiff
Clean up empty directories after rename.
authorAPTX <marek321@gmail.com>
Fri, 26 Apr 2013 18:27:17 +0000 (20:27 +0200)
committerAPTX <marek321@gmail.com>
Fri, 26 Apr 2013 18:27:17 +0000 (20:27 +0200)
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.

localmylist/renamehandler.cpp

index f06b03a543376c756347d16596d059a7286c6142..8b11234ae886711bea56e64c28b6de89fbe861c1 100644 (file)
@@ -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();