[Box Backup-dev] COMMIT r715 - box/chris/general/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sat Aug 5 21:26:34 BST 2006


Author: chris
Date: 2006-08-05 20:26:31 +0000 (Sat, 05 Aug 2006)
New Revision: 715

Modified:
   box/chris/general/lib/common/ExcludeList.cpp
   box/chris/general/lib/common/ExcludeList.h
Log:
* ExcludeList.cpp
* ExcludeList.h
- Match exclude lists case-insensitively and regardless of use of
  forward slashes in paths on Win32


Modified: box/chris/general/lib/common/ExcludeList.cpp
===================================================================
--- box/chris/general/lib/common/ExcludeList.cpp	2006-08-05 20:25:33 UTC (rev 714)
+++ box/chris/general/lib/common/ExcludeList.cpp	2006-08-05 20:26:31 UTC (rev 715)
@@ -65,7 +65,46 @@
 	}
 }
 
+#ifdef WIN32
+std::string ExcludeList::ReplaceSlashesDefinite(const std::string& input) const
+{
+	std::string output = input;
 
+	for (std::string::size_type pos = output.find("/");
+		pos != std::string::npos; 
+		pos = output.find("/"))
+	{
+		output.replace(pos, 1, DIRECTORY_SEPARATOR);
+	}
+
+	for (std::string::iterator i = output.begin(); i != output.end(); i++)
+	{
+		*i = tolower(*i);
+	}
+
+	return output;
+}
+
+std::string ExcludeList::ReplaceSlashesRegex(const std::string& input) const
+{
+	std::string output = input;
+
+	for (std::string::size_type pos = output.find("/");
+		pos != std::string::npos; 
+		pos = output.find("/"))
+	{
+		output.replace(pos, 1, "\\" DIRECTORY_SEPARATOR);
+	}
+
+	for (std::string::iterator i = output.begin(); i != output.end(); i++)
+	{
+		*i = tolower(*i);
+	}
+
+	return output;
+}
+#endif
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -88,7 +127,16 @@
 	{
 		if(i->size() > 0)
 		{
-			mDefinite.insert(*i);
+			std::string entry = *i;
+
+			// Convert any forward slashes in the string
+			// to backslashes
+
+			#ifdef WIN32
+			entry = ReplaceSlashesDefinite(entry);
+			#endif
+
+			mDefinite.insert(entry);
 		}
 	}
 }
@@ -123,8 +171,18 @@
 			
 			try
 			{
+				std::string entry = *i;
+
+				// Convert any forward slashes in the string
+				// to appropriately escaped backslashes
+
+				#ifdef WIN32
+				entry = ReplaceSlashesRegex(entry);
+				#endif
+
 				// Compile
-				if(::regcomp(pregex, i->c_str(), REG_EXTENDED | REG_NOSUB) != 0)
+				if(::regcomp(pregex, entry.c_str(), 
+					REG_EXTENDED | REG_NOSUB) != 0)
 				{
 					THROW_EXCEPTION(CommonException, BadRegularExpression)
 				}
@@ -132,7 +190,7 @@
 				// Store in list of regular expressions
 				mRegex.push_back(pregex);
 				// Store in list of regular expression string for Serialize
-				mRegexStr.push_back(i->c_str());
+				mRegexStr.push_back(entry.c_str());
 			}
 			catch(...)
 			{
@@ -158,10 +216,16 @@
 // --------------------------------------------------------------------------
 bool ExcludeList::IsExcluded(const std::string &rTest) const
 {
+	std::string test = rTest;
+
+	#ifdef WIN32
+	test = ReplaceSlashesDefinite(test);
+	#endif
+
 	// Check against the always include list
 	if(mpAlwaysInclude != 0)
 	{
-		if(mpAlwaysInclude->IsExcluded(rTest))
+		if(mpAlwaysInclude->IsExcluded(test))
 		{
 			// Because the "always include" list says it's 'excluded'
 			// this means it should actually be included.
@@ -170,7 +234,7 @@
 	}
 
 	// Is it in the set of definite entries?
-	if(mDefinite.find(rTest) != mDefinite.end())
+	if(mDefinite.find(test) != mDefinite.end())
 	{
 		return true;
 	}
@@ -180,7 +244,7 @@
 	for(std::vector<regex_t *>::const_iterator i(mRegex.begin()); i != mRegex.end(); ++i)
 	{
 		// Test against this expression
-		if(regexec(*i, rTest.c_str(), 0, 0 /* no match information required */, 0 /* no flags */) == 0)
+		if(regexec(*i, test.c_str(), 0, 0 /* no match information required */, 0 /* no flags */) == 0)
 		{
 			// match happened
 			return true;

Modified: box/chris/general/lib/common/ExcludeList.h
===================================================================
--- box/chris/general/lib/common/ExcludeList.h	2006-08-05 20:25:33 UTC (rev 714)
+++ box/chris/general/lib/common/ExcludeList.h	2006-08-05 20:26:31 UTC (rev 715)
@@ -63,6 +63,11 @@
 	std::vector<std::string> mRegexStr;	// save original regular expression string-based source for Serialize
 #endif
 
+#ifdef WIN32
+	std::string ReplaceSlashesDefinite(const std::string& input) const;
+	std::string ReplaceSlashesRegex   (const std::string& input) const;
+#endif	
+
 	// For exceptions to the excludes
 	ExcludeList *mpAlwaysInclude;
 };




More information about the Boxbackup-dev mailing list