dont accept corrupt sources, improve logs
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 23 May 2006 18:53:00 +0000 (18:53 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 23 May 2006 18:53:00 +0000 (18:53 +0000)
zypp/source/SourceImpl.h
zypp/source/susetags/PackagesLangParser.cc
zypp/source/susetags/PackagesParser.cc
zypp/source/susetags/ProductMetadataParser.cc
zypp/source/susetags/SelectionTagFileParser.cc
zypp/source/susetags/SelectionTagFileParser.h

index 4f05a86..1e5fac3 100644 (file)
@@ -227,10 +227,11 @@ namespace zypp
        */
       virtual media::MediaVerifierRef verifier(unsigned media_nr);
 
-    protected:
       /** Provide Source_Ref back to \c this. */
       Source_Ref selfSourceRef()
       { return Source_Ref( this ); }
+    protected:
+      
 
       /**
        * Provide a file to local filesystem on the given path,
index 60291fb..8e28de0 100644 (file)
@@ -118,7 +118,7 @@ namespace zypp
       void parsePackagesLang( SuseTagsImpl::Ptr sourceimpl, const Pathname & file_r, const Locale & lang_r, const PkgContent & content_r )
       {
         PackagesLangParser p ( sourceimpl, content_r, lang_r);
-       MIL << "Starting with " << content_r.size() << " packages" << endl;
+        MIL <<  "Package descriptions/translations parser: [" << file_r << "]. Source [" << sourceimpl->selfSourceRef().alias() << "] at URL:[" << sourceimpl->selfSourceRef().url().asString() << "]. Starting with " << content_r.size() << " packages" << std::endl;
         try
         {
           p.parse( file_r );
@@ -126,11 +126,11 @@ namespace zypp
         catch(zypp::parser::tagfile::ParseException &e)
         {
           ZYPP_CAUGHT(e);
-          ERR << "Packages Lang " << file_r << " is broken." << std::endl;
+          ERR <<  "Bad Source [" << sourceimpl->selfSourceRef().alias() << "] at URL:[" << sourceimpl->selfSourceRef().url().asString() << "]. Packages descriptions/translations " << file_r << " is broken. You will not see translations." << std::endl;
           return;
         }
 
-        MIL << "packages.LANG parser done. [ Total packages: " << content_r.size() << " ] [ Package data: " << sourceimpl->_package_data.size() << " ]" << std::endl;
+        MIL <<  "Source [" << sourceimpl->selfSourceRef().alias() << "] at URL:[" << sourceimpl->selfSourceRef().url().asString() << "]. packages.LANG parser done. [ Total packages: " << content_r.size() << " ] [ Package data: " << sourceimpl->_package_data.size() << " ]" << std::endl;
         
         return;
       }
index 773bc8b..e222d1f 100644 (file)
@@ -59,7 +59,7 @@ namespace zypp
          {
            std::vector<std::string> words;
            if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 )
-             ZYPP_THROW( ParseException( "Expected [name version release arch], got [" + stag_r.value +"]") );
+              ZYPP_THROW( ParseException( "packages.DU - Expected [name version release arch], got [" + stag_r.value +"]") );
 
            _pkg_pending = true;
            _current_nvrad = NVRAD( words[0], Edition(words[1],words[2]), Arch(words[3]) );
@@ -71,8 +71,8 @@ namespace zypp
          }
          else
          {
-           //ZYPP_THROW( ParseException( "Loc" ) );
-           ERR << "warning found unexpected tag " << stag_r.name << std::endl;
+           //ZYPP_THROW( ParseException( "Unknown tag" ) );
+            ERR << "packages.DU - ERROR! found unexpected tag " << stag_r.name << std::endl;
          }
        }
 
@@ -96,8 +96,7 @@ namespace zypp
              }
              else
              {
-               ERR << "Error parsing package size entry" << "[" << *it << "]" << std::endl;
-               ZYPP_THROW( ParseException( "Dir" ) );
+                ZYPP_THROW( ParseException( std::string("Error parsing package size entry") + "[" + *it + "]" ) );
              }
            }
            result[_current_nvrad] = usage;
@@ -175,7 +174,7 @@ namespace zypp
              capset.insert( CapFactory().parse( ResTraits<Package>::kind, *it ) );
            }
            catch (Exception & excpt_r) {
-             ZYPP_CAUGHT(excpt_r);
+              ZYPP_THROW( ParseException("Bad source ["+ _source.alias() +"] at URL:[" + _source.url().asString() + "]. Can't parse capability: [" + *it + "]" ) );
            }
          }
        }
@@ -195,7 +194,7 @@ namespace zypp
            str::split( stag_r.value, std::back_inserter(words) );
 
            if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 )
-              ZYPP_THROW( ParseException( "Pkg error, we expected NVRA here, got: " + stag_r.value ) );
+              ZYPP_THROW( ParseException("Bad source ["+ _source.alias() +"] at URL:[" + _source.url().asString() + "]. error, we expected NVRA here, got: " + stag_r.value ) );
 
            std::string arch = words[3];
 #warning read comment in file
@@ -224,7 +223,7 @@ namespace zypp
           {
             std::vector<std::string> words;
             if ( str::split( stag_r.value, std::back_inserter(words) ) != 2 )
-              ZYPP_THROW( ParseException( stag_r.name + " - Expected [type checksum], got [" + stag_r.value +"]") );
+              ZYPP_THROW( ParseException("Bad source ["+ _source.alias() +"] at URL:[" + _source.url().asString() + "]. Key: [" + stag_r.name + "] - Expected [type checksum], got [" + stag_r.value +"]"));
 
             _pkgImpl->_checksum = CheckSum(words[0], words[1]);
           }
@@ -235,7 +234,7 @@ namespace zypp
             str::split( stag_r.value, std::back_inserter(words) );
 
             if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 )
-              ZYPP_THROW( ParseException( "Shr tag is wrong, expected NVRA, got: " + stag_r.value ) );
+              ZYPP_THROW( ParseException("Bad source ["+ _source.alias() +"] at URL:[" + _source.url().asString() + "]. Shr tag is wrong, expected NVRA, got: " + stag_r.value ) );
 
             std::string arch = words[3];
             NVRA shared_desc( words[0], Edition( words[1], words[2] ), Arch(arch));
@@ -264,7 +263,7 @@ namespace zypp
          {
            std::vector<std::string> words;
            if ( str::split( stag_r.value, std::back_inserter(words) ) != 2 )
-             ZYPP_THROW( ParseException( "Siz" ) );
+              ZYPP_THROW( ParseException("Bad source ["+ _source.alias() +"] at URL:[" + _source.url().asString() + "]. Siz tag wrong. Got [" + stag_r.value + "]" ) );
 
            _pkgImpl->_archivesize = str::strtonum<unsigned long>(words[0]);
            _pkgImpl->_size = str::strtonum<unsigned long>(words[1]);
@@ -282,7 +281,7 @@ namespace zypp
            }
            else
            {
-               ZYPP_THROW( ParseException( "Loc" ) );
+               ZYPP_THROW( ParseException("Bad source ["+ _source.alias() +"] at URL:[" + _source.url().asString() + "]. Bad [Loc] tag. Got: [" + stag_r.value + "]"));
            }
            // ignore path
          }
@@ -365,8 +364,8 @@ namespace zypp
         catch(zypp::parser::tagfile::ParseException &e)
         {
           ZYPP_CAUGHT(e);
-          ERR << "Package file " << file_r << " is broken." << std::endl;
-          return PkgContent();
+          ERR <<  "Source [" << source_r.alias() << "] at URL:[" << source_r.url().asString() << "] has a broken packages file." << std::endl;
+          ZYPP_RETHROW(e);
         }
        return p.result();
       }
@@ -382,8 +381,8 @@ namespace zypp
         catch(zypp::parser::tagfile::ParseException &e)
         {
           ZYPP_CAUGHT(e);
-          ERR << "Disk usage " << file_r << " is broken." << std::endl;
-          return PkgDiskUsage();
+          ERR <<  "Broken disk usage file " << file_r << ". Ignoring." << std::endl;
+          ZYPP_RETHROW(e);
         }
        return duParser.result;
       }
index b5439e9..4cef8a5 100644 (file)
@@ -59,8 +59,9 @@ namespace zypp
       {
         std::ifstream file(file_r.asString().c_str());
 
-        if (!file) {
-            ZYPP_THROW (Exception("Can't read product file :" + file_r.asString()));
+        if (!file)
+        {
+            ZYPP_THROW (Exception("Bad source ["+ source_r.alias() +"] at URL:[" + source_r.url().asString() + "]. Can't open product file: [" + file_r.asString() + "]"));
         }
 
         std::string buffer;
@@ -73,7 +74,9 @@ namespace zypp
           if(boost::regex_match(buffer, what, e, boost::match_extra))
           {
             if ( what.size() < 5 )
-              std::cout << "ups!!!!" << std::endl;
+            {
+              ZYPP_THROW (Exception("Corrupt source? ["+ source_r.alias() +"] at URL:[" + source_r.url().asString() + "]. Can't parse line: [" + buffer + "]"));
+            }
 
             std::string key = what[2];
             std::string value = what[5];
@@ -127,7 +130,7 @@ namespace zypp
                    }
                    catch( ... )
                    {
-                       // do not add
+                      ZYPP_THROW (Exception("Bad source ["+ source_r.alias() +"] at URL:[" + source_r.url().asString() + "]. Ilegal update Url: [" + *i + "]"));
                    }
                }
            }
@@ -174,11 +177,13 @@ namespace zypp
            else if(key == "VOLATILE_CONTENT")
              volatile_content = true;
             else
-              DBG << "Unknown key [" << key << "] with value [" << value << "]" << std::endl;
+            {
+              ZYPP_THROW (Exception("Corrupt source ["+ source_r.alias() +"] at URL:[" + source_r.url().asString() + "]. Unknown key: [" + key + "] with value [" + value + "]"));
+            }
           }
           else if (!buffer.empty())
           {
-            DBG << "** No Match found:  " << buffer << std::endl;
+            WAR << "Ignoring line [" << buffer << "] in source ["<< source_r.alias() << "] at URL:[" + source_r.url().asString() << "]." << std::endl;
           }
         } // end while
         // finished parsing, store result
@@ -320,7 +325,7 @@ namespace zypp
         str::split( value, std::back_inserter(splitted), " ");
         if (splitted.size() != 3)
         {
-          ERR << "Parse error in checksum. Expected [type checksum file], got [" << value << "]" << std::endl;
+          ZYPP_THROW (Exception("Parse error in checksum entry. Expected [algorithm checksum filename], got [" + value + "]"));
         }
         else
         {
index 9d0dd35..2ae77fc 100644 (file)
@@ -43,7 +43,8 @@ namespace zypp
 
       Selection::Ptr parseSelection( Source_Ref source_r, const Pathname & file_r )
       {
-        MIL << "Starting to parse selection " << file_r << std::endl;
+        MIL <<  "Parsing selection " << file_r << " on source [" << source_r.alias() << "] at URL:[" << source_r.url().asString() << "]." << std::endl;
+        
         SelectionTagFileParser p;
         try
         {
@@ -52,7 +53,8 @@ namespace zypp
         catch(zypp::parser::tagfile::ParseException &e)
         {
           ZYPP_CAUGHT(e);
-          ERR << "Selection " << file_r << " is broken." << std::endl;
+          ERR <<  "Selection " << file_r << " on source [" << source_r.alias() << "] at URL:[" << source_r.url().asString() << "] is broken. Ignoring selection." << std::endl;
+
           return 0L;
         }
         // attach the source
@@ -105,7 +107,7 @@ namespace zypp
               selImpl->_name    = words[0];
               break;
             default:
-              ZYPP_THROW( parser::tagfile::ParseException( "Expected [name [version] [release] [arch] ], got [" + tag.value +"]") );
+              ZYPP_THROW( parser::tagfile::ParseException( "Selection " + _file_r.asString() + ". Expected [name [version] [release] [arch] ], got [" + tag.value +"]"));
               break;
             }
         }
index 010b166..ef3b2bb 100644 (file)
@@ -45,7 +45,7 @@ namespace zypp
       {
         Selection::Ptr result;
         detail::ResImplTraits<SuseTagsSelectionImpl>::Ptr selImpl;
-
+            
         SelectionTagFileParser();
         virtual ~SelectionTagFileParser()
         {}