libzypp  11.13.5
SUSEMediaVerifier.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #include <fstream>
12 
13 using namespace std;
14 
15 namespace zypp
16 {
17 namespace repo
18 {
19 
20 SUSEMediaVerifier::SUSEMediaVerifier(const std::string & vendor_r,
21  const std::string & id_r,
22  const media::MediaNr media_nr)
23  : _media_vendor(vendor_r)
24  , _media_id(id_r)
25  , _media_nr(media_nr)
26 {}
27 
28 SUSEMediaVerifier::SUSEMediaVerifier( int media_nr, const Pathname &path_r )
29  : _media_nr(media_nr)
30 {
31  std::ifstream str(path_r.asString().c_str());
32  std::string vendor;
33  std::string id;
34 
35  if ( str )
36  {
37  getline(str, _media_vendor);
38  getline(str, _media_id);
39  }
40  else
41  {
42  ZYPP_THROW(Exception("Can't setup media verifier using file: '"
43  + path_r.asString() + "'"));
44  }
45 }
46 
48 {
49  if (_media_vendor.empty() || _media_id.empty())
50  return true;
51 
52  Pathname media_file = "/media." + str::numstring(_media_nr) + "/media";
53  ref->provideFile (media_file);
54  media_file = ref->localPath(media_file);
55  std::ifstream str(media_file.asString().c_str());
56  std::string vendor;
57  std::string id;
58 #warning check the stream status
59  getline(str, vendor);
60  getline(str, id);
61 
62  return (vendor == _media_vendor && id == _media_id );
63 }
64 
65 }
66 }
67