Commits

Kimmo Varis committed dd75493

Working a bit for the directory compare.

Now gets a sorted list of QFileInfos and iterates those lists. Prints debug
messages about skipped directories and one-side-only files.

  • Participants
  • Parent commits 22d0364

Comments (0)

Files changed (1)

File lib/dircompare.cpp

 #include <QString>
 #include <QList>
 #include <QStringList>
+#include <QtDebug>
 #include "dircompare.h"
 #include "filecompare.h"
 #include "resultitem.h"
 
 void DirCompare::DoCompare()
 {
-    QStringList left = mLeftDir->entryList();
-    QStringList right = mRightDir->entryList();
+    const QFileInfoList left = mLeftDir->entryInfoList(QDir::NoFilter,
+                               QDir::Name | QDir::DirsFirst);
+    const QFileInfoList right = mRightDir->entryInfoList(QDir::NoFilter,
+                                QDir::Name | QDir::DirsFirst);
 
     mResults.clear();
 
-    QStringList::const_iterator iter = left.constBegin();
-    while (iter != left.constEnd())
+    QFileInfoList::const_iterator iter = left.constBegin();
+    QFileInfoList::const_iterator iter2 = right.constBegin();
+    while (iter != left.constEnd() && iter2 != right.constEnd())
     {
-        int index = right.indexOf(*iter);
-        if (index != -1)
+        const QFileInfo inf1 = *iter;
+        const bool leftIsFile = inf1.isFile();
+        const QFileInfo inf2 = *iter2;
+        const bool rightIsFile = inf2.isFile();
+
+        if (leftIsFile && rightIsFile)
         {
-            QFileInfo inf1(*iter);
-            const bool leftIsFile = inf1.isFile();
-            QFileInfo inf2(right.at(index));
-            const bool rightIsFile = inf2.isFile();
-            if (leftIsFile && rightIsFile)
+            if (inf1.fileName() == inf2.fileName())
             {
-                FileCompare compare(*iter, right.at(index));
+                qDebug() << "Comparing: " << inf1.fileName() << " and " << inf2.fileName();
+                FileCompare compare(inf1.absoluteFilePath(), inf2.absoluteFilePath());
                 ResultItem item = compare.Compare();
                 mResults << item;
+                ++iter;
+                ++iter2;
+            }
+            else
+            {
+                qDebug() << "Skipping one-side item: " << inf1.fileName();
+                ++iter;
             }
         }
-        ++iter;
+        else
+        {
+            if (!leftIsFile)
+            {
+                qDebug() << "Skipping left-side dir: " << inf1.baseName();
+                ++iter;
+            }
+            if (!rightIsFile)
+            {
+                qDebug() << "Skipping right-side dir: " << inf2.baseName();
+                ++iter2;
+            }
+        }
     }
 }