libzypp  10.5.0
SUSEMediaVerifier.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00009 
00010 #include <fstream>
00011 #include "zypp/repo/SUSEMediaVerifier.h"
00012 
00013 using namespace std;
00014 
00015 namespace zypp
00016 {
00017 namespace repo
00018 {
00019 
00020 SUSEMediaVerifier::SUSEMediaVerifier(const std::string & vendor_r,
00021                                      const std::string & id_r,
00022                                      const media::MediaNr media_nr)
00023    : _media_vendor(vendor_r)
00024     , _media_id(id_r)
00025     , _media_nr(media_nr)
00026 {}
00027 
00028 SUSEMediaVerifier::SUSEMediaVerifier( int media_nr, const Pathname &path_r )
00029   : _media_nr(media_nr)
00030 {
00031   std::ifstream str(path_r.asString().c_str());
00032   std::string vendor;
00033   std::string id;
00034   
00035   if ( str )
00036   {
00037     getline(str, _media_vendor);
00038     getline(str, _media_id);
00039   }
00040   else
00041   {
00042     ZYPP_THROW(Exception("Can't setup media verifier using file: '"
00043         + path_r.asString() + "'"));
00044   }
00045 }
00046 
00047 bool SUSEMediaVerifier::isDesiredMedia(const media::MediaAccessRef &ref)
00048 {
00049   if (_media_vendor.empty() || _media_id.empty())
00050     return true;
00051 
00052     Pathname media_file = "/media." + str::numstring(_media_nr) + "/media";
00053     ref->provideFile (media_file);
00054     media_file = ref->localPath(media_file);
00055     std::ifstream str(media_file.asString().c_str());
00056     std::string vendor;
00057     std::string id;
00058 #warning check the stream status
00059     getline(str, vendor);
00060     getline(str, id);
00061 
00062     return (vendor == _media_vendor && id == _media_id );
00063 }
00064 
00065 }
00066 }
00067