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.

Manually cherry-picked from commit d7398464 (tdeutils).

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
r14.0.x
Michele Calgaro 10 years ago
parent 1b697b6bf7
commit b9346aa9e0

@ -52,6 +52,9 @@
#include "commandengine.h" #include "commandengine.h"
#include "whatthis.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; using namespace whatthisNameSpace;
//PUBLIC CONSTRUCTORS //PUBLIC CONSTRUCTORS
@ -71,6 +74,7 @@ TDEFileReplacePart::TDEFileReplacePart(TQWidget* parentWidget, const char* , TQO
m_optionMask = TQDir::Files; m_optionMask = TQDir::Files;
m_w = widget(); m_w = widget();
m_option = 0; m_option = 0;
m_circ_ref_warning_shown = false;
loadOptionsFromRC(); loadOptionsFromRC();
initView(); initView();
@ -130,7 +134,10 @@ void TDEFileReplacePart::slotSearchingOperation()
uint filesNumber = 0; uint filesNumber = 0;
if(m_option->m_recursive) if(m_option->m_recursive)
recursiveFileSearch(currentDirectory, currentFilter, filesNumber); {
m_circ_ref_warning_shown = false;
recursiveFileSearch(currentDirectory, currentFilter, filesNumber, 0);
}
else else
fileSearch(currentDirectory, currentFilter); fileSearch(currentDirectory, currentFilter);
@ -196,7 +203,8 @@ void TDEFileReplacePart::slotReplacingOperation()
if(m_option->m_recursive) if(m_option->m_recursive)
{ {
int filesNumber = 0; int filesNumber = 0;
recursiveFileReplace(currentDirectory, filesNumber); m_circ_ref_warning_shown = false;
recursiveFileReplace(currentDirectory, filesNumber, 0);
} }
else else
{ {
@ -962,11 +970,24 @@ void TDEFileReplacePart::fileReplace()
} }
} }
void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int& filesNumber) void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int& filesNumber, int depth)
{ {
//if m_stop == true then interrupts recursion //if m_stop == true then interrupts recursion
if(m_stop) if(m_stop)
return; return;
else if (!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 else
{ {
TQDir d(directoryName); TQDir d(directoryName);
@ -995,13 +1016,13 @@ void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int
TQFileInfo qi(filePath); TQFileInfo qi(filePath);
m_view->displayScannedFiles(filesNumber); m_view->displayScannedFiles(filesNumber);
kapp->processEvents();
//if filePath is a directory then recursion //if filePath is a directory then recursion
if(qi.isDir()) if(qi.isDir())
recursiveFileReplace(filePath, filesNumber); recursiveFileReplace(filePath, filesNumber, depth+1);
else else
{ {
kapp->processEvents();
if(m_option->m_backup) if(m_option->m_backup)
replaceAndBackup(d.canonicalPath(), fileName); replaceAndBackup(d.canonicalPath(), fileName);
else else
@ -1285,6 +1306,19 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
// if m_stop == true then interrupt recursion // if m_stop == true then interrupt recursion
if(m_stop) if(m_stop)
return; return;
else if (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 else
{ {
TQDir d(directoryName); TQDir d(directoryName);
@ -1312,12 +1346,12 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
m_view->displayScannedFiles(filesNumber); m_view->displayScannedFiles(filesNumber);
kapp->processEvents();
// Searchs recursively if "filePath" is a directory // Searchs recursively if "filePath" is a directory
if(fileInfo.isDir()) if(fileInfo.isDir())
recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber); recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber, depth+1);
else else
{ {
kapp->processEvents();
search(filePath, fileName); search(filePath, fileName);
filesNumber++; filesNumber++;
m_view->displayScannedFiles(filesNumber); m_view->displayScannedFiles(filesNumber);

@ -42,8 +42,9 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
TDEAboutApplication* m_aboutDlg; TDEAboutApplication* m_aboutDlg;
KeyValueMap m_replacementMap; KeyValueMap m_replacementMap;
RCOptions* m_option; RCOptions* m_option;
bool m_stop, bool m_stop;
m_searchingOperation; bool m_searchingOperation;
bool m_circ_ref_warning_shown;
int m_optionMask; int m_optionMask;
public://Constructors public://Constructors
@ -133,7 +134,7 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
* Replacing methods * Replacing methods
*/ */
void fileReplace(); void fileReplace();
void recursiveFileReplace(const TQString& dirName, int& filesNumber); void recursiveFileReplace(const TQString& dirName, int& filesNumber, int depth);
void replaceAndBackup(const TQString& currentDir, const TQString& oldFileName); void replaceAndBackup(const TQString& currentDir, const TQString& oldFileName);
void replaceAndOverwrite(const TQString& currentDir, const TQString& oldFileName); void replaceAndOverwrite(const TQString& currentDir, const TQString& oldFileName);
void replacingLoop(TQString& line, TDEListViewItem** item, bool& atLeastOneStringFound, int& occur, bool regularExpression, bool& askConfirmReplace); void replacingLoop(TQString& line, TDEListViewItem** item, bool& atLeastOneStringFound, int& occur, bool regularExpression, bool& askConfirmReplace);
@ -142,7 +143,7 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
* Searching methods * Searching methods
*/ */
void fileSearch(const TQString& dirName, const TQString& filters); void fileSearch(const TQString& dirName, const TQString& filters);
void recursiveFileSearch(const TQString& dirName, const TQString& filters, uint& filesNumber); void recursiveFileSearch(const TQString& dirName, const TQString& filters, uint& filesNumber, int depth);
void search(const TQString& currentDir, const TQString& fileName); void search(const TQString& currentDir, const TQString& fileName);
/** /**

Loading…
Cancel
Save