faubackup2/src/filesystem dir_parser.cpp,1.5,1.6

Erik Merkel <[email protected]> Wed, 22 Jun 2005 22:56:32 +0000
Newsgroups gmane.comp.sysutils.backup.faubackup.cvs
Message-ID <[email protected]>
Update of /cvsroot/faubackup/faubackup2/src/filesystem
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7274/src/filesystem

Modified Files:
	dir_parser.cpp 
Log Message:
more speed improvments (and some syntax corrections)


Index: dir_parser.cpp
===================================================================
RCS file: /cvsroot/faubackup/faubackup2/src/filesystem/dir_parser.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** dir_parser.cpp	14 Jun 2005 22:10:31 -0000	1.5
--- dir_parser.cpp	22 Jun 2005 22:56:30 -0000	1.6
***************
*** 22,29 ****
  		//		cerr << "true" << endl;
  		if (filter.mode == Filter::include) {
! 			output.information(filename +  " inlude from filter: " + filter.expression, DEBUG_OUTPUT);
  			return Include;
  		} else {
! 			output.information(filename +  " exclude from filter: " + filter.expression, DEBUG_OUTPUT);
  			return Exclude;
  		}
--- 22,29 ----
  		//		cerr << "true" << endl;
  		if (filter.mode == Filter::include) {
! 			output.information(filename + " inlude from filter: " + filter.expression, DEBUG_OUTPUT);
  			return Include;
  		} else {
! 			output.information(filename + " exclude from filter: " + filter.expression, DEBUG_OUTPUT);
  			return Exclude;
  		}
***************
*** 40,50 ****
  	std::list<Filter> localFilterList;
  	struct stat actual_dir_st;
! 	if(dirName != "")
  		actual_dir_st	= getStat(prefix + dirName);
  	else
  		actual_dir_st = getStat(prefix + ".");
! 	output.information(prefix + dirName +  string(CFG_FILENAME) , DEBUG_OUTPUT);
  
! 	if (existFile(prefix + dirName +  string(CFG_FILENAME))) {
  		cfgFile = true;
  		getRulesFromFile(dirName, recursiveFilterList, localFilterList);
--- 40,50 ----
  	std::list<Filter> localFilterList;
  	struct stat actual_dir_st;
! 	if (dirName != "")
  		actual_dir_st	= getStat(prefix + dirName);
  	else
  		actual_dir_st = getStat(prefix + ".");
! 	output.information(prefix + dirName + string(CFG_FILENAME) , DEBUG_OUTPUT);
  
! 	if (existFile(prefix + dirName + string(CFG_FILENAME))) {
  		cfgFile = true;
  		getRulesFromFile(dirName, recursiveFilterList, localFilterList);
***************
*** 65,81 ****
  	while ((entry = readdir(directory)) != NULL) {
  		/* don't backup "." oder ".." entries */
! 		if((strcmp(entry->d_name, "..") == 0) ||
! 		    (strcmp(entry->d_name,".") == 0)   )
  			continue;
  
! 		string filename = prefix + dirName +  string(entry->d_name);
  		//output.information("prefix: " + prefix + " dirname: " + dirName + " entry: " + entry->d_name + " filename: " + filename, NORMAL_OUTPUT);
  
  		/* error treatment */
! 		if(access(filename.c_str(), R_OK) != 0)
! 			if(errno != ENOENT) //symlink defekt
  			{
  				char buffer[1024];
! 				if(getcwd(buffer, 1024) == NULL)
  					output.warning("Could not open file: " + filename, errno);
  				else
--- 65,81 ----
  	while ((entry = readdir(directory)) != NULL) {
  		/* don't backup "." oder ".." entries */
! 		if ((strcmp(entry->d_name, "..") == 0) ||
! 			(strcmp(entry->d_name, ".") == 0) )
  			continue;
  
! 		string filename = prefix + dirName + string(entry->d_name);
  		//output.information("prefix: " + prefix + " dirname: " + dirName + " entry: " + entry->d_name + " filename: " + filename, NORMAL_OUTPUT);
  
  		/* error treatment */
! 		if (access(filename.c_str(), R_OK) != 0)
! 			if (errno != ENOENT) //symlink defekt
  			{
  				char buffer[1024];
! 				if (getcwd(buffer, 1024) == NULL)
  					output.warning("Could not open file: " + filename, errno);
  				else
***************
*** 88,111 ****
  		/*is Directory*/
  		if ((st.st_mode & S_IFMT)
! 		    == S_IFDIR) {
  			/* stay in actual device */
! 			if(!((boundaries) && (st.st_dev != actual_dir_st.st_dev)))
  				/* enter recursive in subdir */
! 				if(parseDir((dirName +  string(entry->d_name) + "/").c_str(),
! 				            recursiveFilterList, globalFilterList) > 0) {
  					/* have files in subdir for backup */
! 					if(_sender)
! 						_sender->send(
! 						        Fileinfo(dirName + entry->d_name,
! 						                 st, MakeBackup), st);
  					filecounter++;
  					continue;
  				}
  		}
! 		if(strcmp(entry->d_name, CFG_FILENAME)== 0) {
  			//	cerr << prefix + dirName << "/" << entry->d_name << endl;
  			// backup configuration in any case
! 			if(_sender)
! 				_sender->send(Fileinfo(dirName + entry->d_name, st, MakeBackup), st);
  
  			filecounter++;
--- 88,113 ----
  		/*is Directory*/
  		if ((st.st_mode & S_IFMT)
! 			== S_IFDIR) {
  			/* stay in actual device */
! 			if (!((boundaries) && (st.st_dev != actual_dir_st.st_dev)))
  				/* enter recursive in subdir */
! 				if (parseDir((dirName + string(entry->d_name) + "/").c_str(),
! 					     recursiveFilterList, globalFilterList) > 0) {
  					/* have files in subdir for backup */
! 					Fileinfo info(dirName + entry->d_name,
! 						      st, MakeBackup);
! 					if (_sender)
! 						_sender->send(info, st);
  					filecounter++;
  					continue;
  				}
  		}
! 		if (strcmp(entry->d_name, CFG_FILENAME) == 0) {
  			//	cerr << prefix + dirName << "/" << entry->d_name << endl;
  			// backup configuration in any case
! 			Fileinfo info(dirName + entry->d_name,
! 				      st, MakeBackup);
! 			if (_sender)
! 				_sender->send(info, st);
  
  			filecounter++;
***************
*** 113,134 ****
  		}
  		FilterMatchType result;
! 		if(cfgFile) {
  			result = testRules(dirName + entry->d_name,
! 			                   localFilterList);
! 			if(result == Match_with_date) {
! 				if(_sender)
! 					_sender->send(Fileinfo(dirName + entry->d_name, st, MakeBackup), st);
  				filecounter++;
  				continue;
  			}
! 			if(result == Match_exclude_with_date)  {
  				/* nothing to do */
  				continue;
  			}
  
! 			if((result == Match_with_wrong_date) ||
! 			    (result == Match_exclude_with_wrong_date)) {
! 				if(_sender)
! 					_sender->send(Fileinfo(dirName + entry->d_name, st, KeepExisting), st);
  				filecounter++;
  				continue;
--- 115,140 ----
  		}
  		FilterMatchType result;
! 		if (cfgFile) {
  			result = testRules(dirName + entry->d_name,
! 					   localFilterList);
! 			if (result == Match_with_date) {
! 				Fileinfo info(dirName + entry->d_name,
! 					      st, MakeBackup);
! 				if (_sender)
! 					_sender->send(info, st);
  				filecounter++;
  				continue;
  			}
! 			if (result == Match_exclude_with_date) {
  				/* nothing to do */
  				continue;
  			}
  
! 			if ((result == Match_with_wrong_date) ||
! 				(result == Match_exclude_with_wrong_date)) {
! 				Fileinfo info(dirName + entry->d_name,
! 					      st, KeepExisting);
! 				if (_sender)
! 					_sender->send(info, st);
  				filecounter++;
  				continue;
***************
*** 138,157 ****
  		/* recursive Filter */
  		result = testRules(dirName + entry->d_name,
! 		                   recursiveFilterList);
! 		if(result == Match_with_date) {
! 			if(_sender)
! 				_sender->send(Fileinfo(dirName + entry->d_name, st, MakeBackup), st);
  			filecounter++;
  			continue;
  		}
! 		if(result == Match_exclude_with_date)  {
  			/* nothing to do */
  			continue;
  		}
! 
! 		if((result == Match_with_wrong_date) ||
! 		    (result == Match_exclude_with_wrong_date)) {
! 			if(_sender)
! 				_sender->send(Fileinfo(dirName + entry->d_name, st, KeepExisting), st);
  			filecounter++;
  			continue;
--- 144,166 ----
  		/* recursive Filter */
  		result = testRules(dirName + entry->d_name,
! 				   recursiveFilterList);
! 		if (result == Match_with_date) {
! 			Fileinfo info(dirName + entry->d_name,
! 				      st, MakeBackup);
! 			if (_sender)
! 				_sender->send(info, st);
  			filecounter++;
  			continue;
  		}
! 		if (result == Match_exclude_with_date) {
  			/* nothing to do */
  			continue;
  		}
! 		if ((result == Match_with_wrong_date) ||
! 			(result == Match_exclude_with_wrong_date)) {
! 			Fileinfo info(dirName + entry->d_name,
! 				      st, KeepExisting);
! 			if (_sender)
! 				_sender->send(info, st);
  			filecounter++;
  			continue;
***************
*** 160,189 ****
  		/* global Filter */
  		result = testRules(dirName + entry->d_name,
! 		                   globalFilterList);
! 		if(result == Match_with_date) {
! 			if(_sender)
! 				_sender->send(Fileinfo(dirName + entry->d_name, st, MakeBackup), st);
  			filecounter++;
  			continue;
  		}
! 		if(result == Match_exclude_with_date)  {
  			/* nothing to do */
  			continue;
  		}
  
! 		if((result == Match_with_wrong_date) ||
! 		    (result == Match_exclude_with_wrong_date)) {
! 			if(_sender)
! 				_sender->send(Fileinfo(dirName + entry->d_name, st, KeepExisting), st);
  			filecounter++;
  			continue;
  		}
  		/* no Filter machted */
! 		if(_sender)
! 			_sender->send(Fileinfo(dirName + entry->d_name, st, KeepExisting), st);
  		filecounter++;
  	}
  
! 	if(closedir(directory)!= 0)
  		output.warning("error closing directory " + prefix + dirName, errno);
  	return filecounter;
--- 169,205 ----
  		/* global Filter */
  		result = testRules(dirName + entry->d_name,
! 				   globalFilterList);
! 		if (result == Match_with_date) {
! 			Fileinfo info(dirName + entry->d_name,
! 				      st, MakeBackup);
! 			if (_sender)
! 				_sender->send(info, st);
  			filecounter++;
  			continue;
  		}
! 		if (result == Match_exclude_with_date) {
  			/* nothing to do */
  			continue;
  		}
  
! 		if ((result == Match_with_wrong_date) ||
! 			(result == Match_exclude_with_wrong_date)) {
! 			Fileinfo info(dirName + entry->d_name,
! 				      st, KeepExisting);
! 			if (_sender)
! 				_sender->send(info, st);
  			filecounter++;
  			continue;
  		}
  		/* no Filter machted */
! 		Fileinfo info(dirName + entry->d_name,
! 			      st, KeepExisting);
! 
! 		if (_sender)
! 			_sender->send(info, st);
  		filecounter++;
  	}
  
! 	if (closedir(directory) != 0)
  		output.warning("error closing directory " + prefix + dirName, errno);
  	return filecounter;
***************
*** 194,199 ****
  	this->_sender = NULL;
  	this->globalConfig = NULL;
! 	if(startdir != "")
! 		if(startdir[startdir.length()-1] != '/')
  			startdir.append("/");
  
--- 210,215 ----
  	this->_sender = NULL;
  	this->globalConfig = NULL;
! 	if (startdir != "")
! 		if (startdir[startdir.length() - 1] != '/')
  			startdir.append("/");
  
***************
*** 220,224 ****
  
  	output.information("parse complete!", DEBUG_OUTPUT);
! 	if(_sender)
  		_sender->sendfinish();
  }
--- 236,240 ----
  
  	output.information("parse complete!", DEBUG_OUTPUT);
! 	if (_sender)
  		_sender->sendfinish();
  }
***************
*** 236,241 ****
  	} else
  		globallist = globalConfig->getdefaultRules();
! 	if(startdir != "")
! 		if(startdir[startdir.length()-1] != '/')
  			startdir.append("/");
  
--- 252,257 ----
  	} else
  		globallist = globalConfig->getdefaultRules();
! 	if (startdir != "")
! 		if (startdir[startdir.length() - 1] != '/')
  			startdir.append("/");
  
***************
*** 244,248 ****
  
  	output.information("parse complete!", DEBUG_OUTPUT);
! 	if(_sender)
  		_sender->sendfinish();
  }
--- 260,264 ----
  
  	output.information("parse complete!", DEBUG_OUTPUT);
! 	if (_sender)
  		_sender->sendfinish();
  }
***************
*** 260,265 ****
  	} else
  		globallist = globalConfig->getdefaultRules();
! 	if(startdir != "")
! 		if(startdir[startdir.length()-1] != '/')
  			startdir.append("/");
  	prefix = startdir;
--- 276,281 ----
  	} else
  		globallist = globalConfig->getdefaultRules();
! 	if (startdir != "")
! 		if (startdir[startdir.length() - 1] != '/')
  			startdir.append("/");
  	prefix = startdir;
***************
*** 274,278 ****
  	parseDir("", emptylist, globallist);
  	output.information("parse complete!", DEBUG_OUTPUT);
! 	if(_sender)
  		_sender->sendfinish();
  
--- 290,294 ----
  	parseDir("", emptylist, globallist);
  	output.information("parse complete!", DEBUG_OUTPUT);
! 	if (_sender)
  		_sender->sendfinish();
  
***************
*** 292,300 ****
  
  void DirectoryParser::getRulesFromFile(string dirName,
!                                        std::list<Filter> &recursiveFilterList,
!                                        std::list<Filter> &localFilterList)
  {
! 	ControlFileParser parser(prefix + dirName +  string(CFG_FILENAME),
! 	                         dirName, globalConfig);
  	std::list<Filter>::iterator i;
  	/* get the local rules */
--- 308,316 ----
  
  void DirectoryParser::getRulesFromFile(string dirName,
! 				       std::list<Filter> &recursiveFilterList,
! 				       std::list<Filter> &localFilterList)
  {
! 	ControlFileParser parser(prefix + dirName + string(CFG_FILENAME),
! 				 dirName, globalConfig);
  	std::list<Filter>::iterator i;
  	/* get the local rules */
***************
*** 304,312 ****
  	i = recursiveFilterList.begin();
  	std::list<Filter> temp_rec = parser.getRecursiveRules();
! 	if(!temp_rec.empty()) {
! 		if(!recursiveFilterList.empty()) {
! 			recursiveFilterList.splice(i,temp_rec );
  		} else {
! 			recursiveFilterList=temp_rec;
  		}
  	}
--- 320,328 ----
  	i = recursiveFilterList.begin();
  	std::list<Filter> temp_rec = parser.getRecursiveRules();
! 	if (!temp_rec.empty()) {
! 		if (!recursiveFilterList.empty()) {
! 			recursiveFilterList.splice(i, temp_rec );
  		} else {
! 			recursiveFilterList = temp_rec;
  		}
  	}
***************
*** 314,338 ****
  
  DirectoryParser::FilterMatchType DirectoryParser::testRules(string filename,
!                 std::list<Filter> &filterList)
  {
  	FilterMatchType result = NoMatch;
! 	if(filterList.empty())
  		return NoMatch;
  	std::list<Filter>::iterator i;
  
  	i = filterList.begin();
! 	while(i != filterList.end()) {
  		bool valid = matchBetweenIntervals(lastbackup,
! 		                                   actualbackup,
! 		                                   i->filterTime);
  		enum ExpressionMatchType cmp_result = compare(*i, filename);
! 		if (cmp_result == Include) {// backup it
! 			if(valid)
  				return Match_with_date;
  			else
  				result = Match_with_wrong_date;
  		} else
! 			if (cmp_result == Exclude) {//ignore it
! 				if(valid)
  					return Match_exclude_with_date;
  				else
--- 330,354 ----
  
  DirectoryParser::FilterMatchType DirectoryParser::testRules(string filename,
! 							    std::list<Filter> &filterList)
  {
  	FilterMatchType result = NoMatch;
! 	if (filterList.empty())
  		return NoMatch;
  	std::list<Filter>::iterator i;
  
  	i = filterList.begin();
! 	while (i != filterList.end()) {
  		bool valid = matchBetweenIntervals(lastbackup,
! 						   actualbackup,
! 						   i->filterTime);
  		enum ExpressionMatchType cmp_result = compare(*i, filename);
! 		if (cmp_result == Include) { // backup it
! 			if (valid)
  				return Match_with_date;
  			else
  				result = Match_with_wrong_date;
  		} else
! 			if (cmp_result == Exclude) { //ignore it
! 				if (valid)
  					return Match_exclude_with_date;
  				else



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click