summaryrefslogtreecommitdiffstats
path: root/tdefilereplace
diff options
context:
space:
mode:
Diffstat (limited to 'tdefilereplace')
-rw-r--r--tdefilereplace/tdefilereplacepart.cpp48
-rw-r--r--tdefilereplace/tdefilereplacepart.h9
2 files changed, 46 insertions, 11 deletions
diff --git a/tdefilereplace/tdefilereplacepart.cpp b/tdefilereplace/tdefilereplacepart.cpp
index e0bb9f97..e91fa462 100644
--- a/tdefilereplace/tdefilereplacepart.cpp
+++ b/tdefilereplace/tdefilereplacepart.cpp
@@ -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)
- recursiveFileSearch(currentDirectory, currentFilter, filesNumber);
+ {
+ m_circ_ref_warning_shown = false;
+ recursiveFileSearch(currentDirectory, currentFilter, filesNumber, 0);
+ }
else
fileSearch(currentDirectory, currentFilter);
@@ -196,7 +203,8 @@ void TDEFileReplacePart::slotReplacingOperation()
if(m_option->m_recursive)
{
int filesNumber = 0;
- recursiveFileReplace(currentDirectory, filesNumber);
+ m_circ_ref_warning_shown = false;
+ recursiveFileReplace(currentDirectory, filesNumber, 0);
}
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)
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
{
TQDir d(directoryName);
@@ -995,13 +1016,13 @@ void TDEFileReplacePart::recursiveFileReplace(const TQString& directoryName, int
TQFileInfo qi(filePath);
m_view->displayScannedFiles(filesNumber);
+ kapp->processEvents();
//if filePath is a directory then recursion
if(qi.isDir())
- recursiveFileReplace(filePath, filesNumber);
+ recursiveFileReplace(filePath, filesNumber, depth+1);
else
{
- kapp->processEvents();
if(m_option->m_backup)
replaceAndBackup(d.canonicalPath(), fileName);
else
@@ -1285,6 +1306,19 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
// if m_stop == true then interrupt recursion
if(m_stop)
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
{
TQDir d(directoryName);
@@ -1312,12 +1346,12 @@ void TDEFileReplacePart::recursiveFileSearch(const TQString& directoryName, cons
m_view->displayScannedFiles(filesNumber);
+ kapp->processEvents();
// Searchs recursively if "filePath" is a directory
if(fileInfo.isDir())
- recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber);
+ recursiveFileSearch(filePath+"/"+fileName, filters, filesNumber, depth+1);
else
{
- kapp->processEvents();
search(filePath, fileName);
filesNumber++;
m_view->displayScannedFiles(filesNumber);
diff --git a/tdefilereplace/tdefilereplacepart.h b/tdefilereplace/tdefilereplacepart.h
index 0ca917e0..34a91dae 100644
--- a/tdefilereplace/tdefilereplacepart.h
+++ b/tdefilereplace/tdefilereplacepart.h
@@ -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
@@ -133,7 +134,7 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
* Replacing methods
*/
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 replaceAndOverwrite(const TQString& currentDir, const TQString& oldFileName);
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
*/
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);
/**