Mercurial > dedupe
comparison DataController.cpp @ 89:cfd2a417475a
Avoid multiple filesystem searches.
Some cosmetics.
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Mon, 21 Oct 2013 16:19:23 +0200 |
| parents | 848496a57039 |
| children | 308a718812ba |
comparison
equal
deleted
inserted
replaced
| 88:6e1d4d2fc49b | 89:cfd2a417475a |
|---|---|
| 39 try { | 39 try { |
| 40 wpath = dir_iter->path().wstring(); | 40 wpath = dir_iter->path().wstring(); |
| 41 } | 41 } |
| 42 catch (boost::system::system_error &e) { | 42 catch (boost::system::system_error &e) { |
| 43 printf("%s\n", dir_iter->path().c_str()); | 43 printf("%s\n", dir_iter->path().c_str()); |
| 44 std::cout << e.what() <<std::endl; | 44 std::cout << e.what() << std::endl; |
| 45 } | 45 } |
| 46 if (!wpath.empty()) { | 46 if (!wpath.empty()) { |
| 47 if (fs::is_directory(dir_iter->status()) ) { | 47 if (fs::is_directory(dir_iter->status()) ) { |
| 48 findFiles(QString::fromStdWString(wpath), list); | 48 findFiles(QString::fromStdWString(wpath), list); |
| 49 } | 49 } |
| 73 return list; | 73 return list; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void DataController::findFiles(const QDir& dir, FileDBLink& dblink) | 76 void DataController::findFiles(const QDir& dir, FileDBLink& dblink) |
| 77 { | 77 { |
| 78 QStringList list = findFiles(dir); | 78 QStringList paths = findFiles(dir); |
| 79 | 79 |
| 80 QDateTime last = QDateTime::currentDateTime(); | 80 QDateTime last = QDateTime::currentDateTime(); |
| 81 | 81 |
| 82 dblink.keepOnlyFromPrefix(dir.path(), list); | 82 dblink.keepOnlyFromPrefix(dir.path(), paths); |
| 83 | 83 |
| 84 std::auto_ptr<QProgressBar> bar; | 84 std::auto_ptr<QProgressBar> bar; |
| 85 | 85 |
| 86 progressMax = list.size(); | 86 progressMax = paths.size(); |
| 87 | 87 |
| 88 if (showGUI) { | 88 if (showGUI) { |
| 89 bar = std::auto_ptr<QProgressBar>(new QProgressBar()); | 89 bar = std::auto_ptr<QProgressBar>(new QProgressBar()); |
| 90 | 90 |
| 91 bar->resize(200,25); | 91 bar->resize(200,25); |
| 98 bar.get(), SLOT(setValue(int))); | 98 bar.get(), SLOT(setValue(int))); |
| 99 } | 99 } |
| 100 | 100 |
| 101 int n = 0; | 101 int n = 0; |
| 102 emit populateProgress(n); | 102 emit populateProgress(n); |
| 103 foreach(QString filename, findFiles(dir)) { | 103 |
| 104 foreach(QString filename, paths) { | |
| 104 try { | 105 try { |
| 105 dblink.updateIfModified(filename); | 106 dblink.updateIfModified(filename); |
| 106 } | 107 } |
| 107 catch (const PermissionException& e) { | 108 catch (const PermissionException& e) { |
| 108 dblink.deleteFileFromDB(filename); | 109 dblink.deleteFileFromDB(filename); |
