but showing the error line.
Last fix making the parser relax would break multitag
descriptions with empty lines, now we check dependencies
at a higher level. (reference #160607)
int new_progress = 0;
_file_r = file_r;
_file_size = 0;
- _no_lines = 0;
+ _line_number = 0;
_file_size = PathInfo(file_r).size();
std::ifstream file(file_r.asString().c_str());
int readed = 0;
while(file && !file.eof())
{
getline(file, buffer);
+ _line_number++;
readed += buffer.size();
boost::smatch what;
std::string element;
boost::smatch element_what;
getline(file, element);
+ _line_number++;
readed += element.size();
// while we dont find the list terminator
while(!file.eof())
}
}
- // skip empty lines and comments inside lists
- if ( ! ( element.empty() || ( element[0] == '#' ) ) )
- {
- tag.values.push_back(element);
- }
+ tag.values.push_back(element);
XXX << element << std::endl;
getline(file, element);
+ _line_number++;
readed += element.size();
//dumpRegexpResults(element_what);
}
// before we used to throw a parse error exception if we dont find
// a key value line. But package descriptions usually are broken
// and contain multiple lines for single line tags, etc.
- // so now we just skip those lines.
- //ZYPP_THROW(ParseException("parse error: " + buffer));
- ERR << "Parse error, unrecognized format [" << buffer << "]. Be sure " << _file_r << "does not contains a single tag with new lines." << std::endl;
+ stringstream ss;
+ ss << "Parse error, unrecognized line [" << buffer << "]. Be sure " << _file_r << " line " << _line_number << " misses a tag or comment.";
+ ZYPP_THROW( ParseException( ss.str() ) );
}
new_progress = (int)((((float)readed)/((float)_file_size))*100);
ParserProgress::Ptr _progress;
Pathname _file_r;
int _file_size;
- int _no_lines;
+ int _line_number;
};
/////////////////////////////////////////////////////////////////
} // namespace parser
/** \file zypp/source/susetags/PackagesParser.cc
*
*/
+#include <sstream>
#include <iostream>
#include <boost/regex.hpp>
#include "zypp/ZYppFactory.h"
using std::endl;
+using namespace std;
///////////////////////////////////////////////////////////////////
namespace zypp
for ( std::list<std::string>::const_iterator it = depstr_r.begin();
it != depstr_r.end(); ++it )
{
+ if ( (*it).empty() )
+ {
+ stringstream ss;
+ ss << "Bad source [" << _source.alias() << "] at URL:[" << _source.url().asString() << "]. Emtpy capability on " << _file_r << " line " << _line_number;
+ ZYPP_THROW( ParseException( ss.str() ) );
+ }
+
try
{
capset.insert( CapFactory().parse( ResTraits<Package>::kind, *it ) );
}
catch (Exception & excpt_r)
{
- ZYPP_THROW( ParseException("Bad source ["+ _source.alias() +"] at URL:[" + _source.url().asString() + "]. Can't parse capability: [" + *it + "]" ) );
+ stringstream ss;
+ ss << "Bad source [" << _source.alias() << "] at URL:[" << _source.url().asString() << "]. Can't parse capability: [" << *it << "] on " << _file_r << " line " << _line_number;
+ ZYPP_THROW( ParseException( ss.str() ) );
}
}
}
#include "zypp/CapFactory.h"
#include "zypp/source/susetags/PatternTagFileParser.h"
+#include "zypp/parser/tagfile/ParseException.h"
#include <boost/regex.hpp>
#undef ZYPP_BASE_LOGGER_LOGGROUP
using namespace std;
using namespace boost;
+using namespace zypp::parser::tagfile;
///////////////////////////////////////////////////////////////////
namespace zypp
}
}
-static void parseDeps( const std::list<std::string> & strdeps, CapSet & capset, const Resolvable::Kind & kind = ResTraits<Pattern>::kind )
+void PatternTagFileParser::parseDeps( const std::list<std::string> & strdeps, CapSet & capset, const Resolvable::Kind & kind )
{
CapFactory f;
for (std::list<std::string>::const_iterator it = strdeps.begin(); it != strdeps.end(); it++)
- {
- Capability cap = f.parse( kind, *it );
- capset.insert( cap );
+ {
+ if ( (*it).empty() )
+ {
+ stringstream ss;
+ ss << "Emtpy capability on " << _file_r << " line " << _line_number;
+ ZYPP_THROW( ParseException( ss.str() ) );
+ }
+
+ try
+ {
+ Capability cap = f.parse( kind, *it );
+ capset.insert( cap );
+ }
+ catch ( const Exception &e )
+ {
+ stringstream ss;
+ ss << "Broken capability [" << *it << "]" << _file_r << " line " << _line_number;
+ ZYPP_THROW( ParseException( ss.str() ) );
+ }
}
return;
}
virtual ~PatternTagFileParser()
{}
+ void parseDeps( const std::list<std::string> & strdeps, CapSet & capset, const Resolvable::Kind & kind = ResTraits<Pattern>::kind );
+
void consume( const SingleTag &tag );
void consume( const MultiTag &tag );
void endParse();