void LinkBackupThread::processDir(QDir& currentFromDir, QDir& currentToDir) { long numErrors = getLogger().errorCount(); if (numErrors > 1000) { QString errorMessage = QString("%1 errors found, quit?"); QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "Test", errorMessage, QMessageBox::Yes|QMessageBox::No); if (reply == QMessageBox::Yes) { requestCancel(); } else { getLogger().clearErrorCount(); } } TRACE_MSG(QString("Processing directory %1").arg(currentFromDir.canonicalPath()), 1); // Process directories, then process files. QList<QFileInfo> list = currentFromDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::Hidden | QDir::Readable); QFileInfo info; foreach (info, list) { if (isCancelRequested()) { return; } TRACE_MSG(QString("Found Dir to processes %1").arg(info.canonicalFilePath()), 2); if (passes(info)) { DEBUG_MSG(QString("Dir Passes: %1").arg(info.canonicalFilePath()), 2); if (!currentToDir.mkdir(info.fileName())) { ERROR_MSG(QString("Failed to create directory %1/%2").arg(currentToDir.canonicalPath(), info.fileName()), 1); } else if (!currentToDir.cd(info.fileName())) { ERROR_MSG(QString("Failed to cd to directory %1/%2").arg(currentToDir.canonicalPath(), info.fileName()), 1); } else if (!currentFromDir.cd(info.fileName())) { ERROR_MSG(QString("Failed to cd to directory %1/%2").arg(currentFromDir.canonicalPath(), info.fileName()), 1); if (!currentToDir.cdUp()) { ERROR_MSG("Failed to cd up a directory for the to directory", 1); requestCancel(); return; } } else { processDir(currentFromDir, currentToDir); if (!currentToDir.cdUp()) { ERROR_MSG("Failed to cd up a directory for the to directory", 1); requestCancel(); return; } if (!currentFromDir.cdUp()) { ERROR_MSG("Failed to cd up a directory for the from directory", 1); requestCancel(); return; } } } else { DEBUG_MSG(QString("Skipping Dir: %1").arg(info.canonicalFilePath()), 2); } } // Now handle files list = currentFromDir.entryInfoList(QDir::Files | QDir::NoSymLinks | QDir::Hidden | QDir::Readable); foreach (info, list) { if (isCancelRequested()) { return; } QString fullPathFileToRead = info.canonicalFilePath(); //TRACE_MSG(QString("Found File to test %1").arg(fullPathFileToRead), 2); if (passes(info)) { //TRACE_MSG(QString("File passes %1").arg(fullPathFileToRead), 2); QFile fileToRead(fullPathFileToRead); // Just in case someone deleted the file. if (fileToRead.exists()) { DBFileEntry* currentEntry = new DBFileEntry(info, m_fromDirWithoutTopDirName); const DBFileEntry* linkEntry = m_oldEntries->findEntry(m_backupSet.getCriteria(), currentEntry, m_fromDirWithoutTopDirName); QString pathToLinkFile = m_previousDirRoot; // If not in the old backup, search the current backup. if (linkEntry == nullptr) { linkEntry = m_currentEntries->findEntry(m_backupSet.getCriteria(), currentEntry, m_fromDirWithoutTopDirName); pathToLinkFile = m_toDirRoot; } if (linkEntry == nullptr) { bool failedToCopy = false; QString fullFileNameToWrite = m_toDirRoot + "/" + currentEntry->getPath(); bool needHash = (currentEntry->getHash().length() == 0); if (needHash) { failedToCopy = !::getCopyLinkUtil().copyFileGenerateHash(fullPathFileToRead, fullFileNameToWrite); if (!failedToCopy) { currentEntry->setHash(getCopyLinkUtil().getLastHash()); } } else if (!getCopyLinkUtil().copyFile(fullPathFileToRead, fullFileNameToWrite)) { failedToCopy = true; } if (failedToCopy) { ERROR_MSG(QString(tr("EC %1")).arg(currentEntry->getPath()), 1); } else { INFO_MSG(QString(tr("C %1")).arg(currentEntry->getPath()), 1); currentEntry->setLinkTypeCopy(); m_currentEntries->addEntry(currentEntry); currentEntry = nullptr; } } else { if (getCopyLinkUtil().linkFile(pathToLinkFile + "/" + linkEntry->getPath(), m_toDirRoot + "/" + currentEntry->getPath())) { currentEntry->setLinkTypeLink(); currentEntry->setHash(linkEntry->getHash()); m_currentEntries->addEntry(currentEntry); INFO_MSG(QString(tr("L %1")).arg(currentEntry->getPath()), 1); currentEntry = nullptr; } else { ERROR_MSG(QString(tr("EL %1")).arg(currentEntry->getPath()), 1); ERROR_MSG(QString(tr("(%1)(%2)(%3)")).arg(pathToLinkFile, linkEntry->getPath(), m_toDirRoot), 1); } } if (currentEntry != nullptr) { delete currentEntry; currentEntry= nullptr; } } } } TRACE_MSG(QString("Finished with directory %1").arg(currentFromDir.canonicalPath()), 1); }
void CProgressDlg::on_cancelBtn_clicked() { emit requestCancel(); }