TDEFileReplace: fixed unresponsive GUI and application crash when circular references are found on the file system.

Added a message to advice the user of the possible circular reference. This relates to bug 2264.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/1/head
Michele Calgaro 11 years ago
parent 23b906b576
commit d7398464a9

@ -52,6 +52,9 @@
#include "commandengine.h"
#include "whatthis.h"
// Change this as well if increasing the max value allowed for the m_spbMaxDepth spinbox
static const int CIRCULAR_LINK_DETECTION_LEVEL = 256;
using namespace whatthisNameSpace;
//PUBLIC CONSTRUCTORS
@ -71,6 +74,7 @@ TDEFileReplacePart::TDEFileReplacePart(TQWidget* parentWidget, const char* , TQO
m_optionMask = TQDir::Files;
m_w = widget();
m_option = 0;
m_circ_ref_warning_shown = false;
loadOptionsFromRC();
initView();
@ -130,7 +134,10 @@ void TDEFileReplacePart::slotSearchingOperation()
uint filesNumber = 0;
if(m_option->m_recursive)
{
m_circ_ref_warning_shown = false;
recursiveFileSearch(currentDirectory, currentFilter, filesNumber, 0);
}
else
fileSearch(currentDirectory, currentFilter);
@ -196,6 +203,7 @@ void TDEFileReplacePart::slotReplacingOperation()
if(m_option->m_recursive)
{
int filesNumber = 0;
m_circ_ref_warning_shown = false;
recursiveFileReplace(currentDirectory, filesNumber, 0);
}
else
@ -972,6 +980,19 @@ void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int
// if m_stop == true or the max depth level is reached, then interrupt recursion
if (m_stop || (m_option->m_limitDepth && depth > m_option->m_maxDepth))
return;
else if (!m_option->m_limitDepth && depth > CIRCULAR_LINK_DETECTION_LEVEL)
{
if (!m_circ_ref_warning_shown)
{
KMessageBox::information(m_w,
i18n("It seems you have a circular reference in your file system."
"The search has been limited to this sublevel to prevent"
"TDEFileReplace from crashing."),
i18n("Circular reference detected"));
m_circ_ref_warning_shown = true;
}
return;
}
else
{
TQDir d(directoryName);
@ -985,7 +1006,6 @@ void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int
for(filesIt = filesList.begin(); filesIt != filesList.end(); ++filesIt)
{
//if m_stop == true then end for-loop
if(m_stop)
break;
@ -1001,6 +1021,7 @@ void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int
m_view->displayScannedFiles(filesNumber);
kapp->processEvents();
// Replace recursively if "filePath" is a directory and we have not reached the max depth level
if (qi.isDir())
{
@ -1011,7 +1032,6 @@ void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int
}
else
{
kapp->processEvents();
if(m_option->m_backup)
replaceAndBackup(d.canonicalPath(), fileName);
else
@ -1296,6 +1316,19 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
// if m_stop == true or the max depth level is reached, then interrupt recursion
if (m_stop || (m_option->m_limitDepth && depth > m_option->m_maxDepth))
return;
else if (!m_option->m_limitDepth && depth > CIRCULAR_LINK_DETECTION_LEVEL)
{
if (!m_circ_ref_warning_shown)
{
KMessageBox::information(m_w,
i18n("It seems you have a circular reference in your file system. "
"The search has been limited to this sublevel to prevent "
"TDEFileReplace from crashing."),
i18n("Circular reference detected"));
m_circ_ref_warning_shown = true;
}
return;
}
else
{
TQDir d(directoryName);
@ -1309,7 +1342,6 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
for(filesIt = filesList.begin(); filesIt != filesList.end(); ++filesIt)
{
// stop polling
if(m_stop)
break;
@ -1323,6 +1355,7 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
m_view->displayScannedFiles(filesNumber);
kapp->processEvents();
// Searchs recursively if "filePath" is a directory and we have not reached the max depth level
if (fileInfo.isDir())
{
@ -1333,7 +1366,6 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
}
else
{
kapp->processEvents();
search(filePath, fileName);
filesNumber++;
m_view->displayScannedFiles(filesNumber);

@ -42,8 +42,9 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
TDEAboutApplication* m_aboutDlg;
KeyValueMap m_replacementMap;
RCOptions* m_option;
bool m_stop,
m_searchingOperation;
bool m_stop;
bool m_searchingOperation;
bool m_circ_ref_warning_shown;
int m_optionMask;
public://Constructors

Loading…
Cancel
Save