libzypp 17.25.7
SUSEMediaVerifier.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#include <fstream>
11#include <zypp/base/Logger.h>
13
14using std::endl;
15
16namespace zypp
17{
18namespace repo
19{
20
21SUSEMediaVerifier::SUSEMediaVerifier(const std::string & vendor_r,
22 const std::string & id_r,
23 const media::MediaNr media_nr)
24 : _media_vendor(vendor_r)
25 , _media_id(id_r)
26 , _media_nr(media_nr)
27{}
28
29SUSEMediaVerifier::SUSEMediaVerifier( int media_nr, const Pathname &path_r )
30 : _media_nr(media_nr)
31{
32 std::ifstream str(path_r.asString().c_str());
33 std::string vendor;
34 std::string id;
35
36 if ( str )
37 {
40 }
41 else
42 {
43 ZYPP_THROW(Exception("Can't setup media verifier using file: '"
44 + path_r.asString() + "'"));
45 }
46}
47
49{
50 if (_media_vendor.empty() || _media_id.empty())
51 return true;
52
53 Pathname media_file = "/media." + str::numstring(_media_nr) + "/media";
54 ref->provideFile (media_file, 0);
55 media_file = ref->localPath(media_file);
56 std::ifstream str(media_file.asString().c_str());
57 std::string vendor;
58 std::string id;
59 getline(str, vendor);
60 getline(str, id);
61
62 bool ret = ( vendor == _media_vendor && id == _media_id );
63 if ( !ret ) {
64 DBG << "cached vendor: " << _media_vendor << endl;
65 DBG << "repo vendor: " << vendor << endl;
66 DBG << "cached id: " << _media_id << endl;
67 DBG << "repo id: " << id << endl;
68 }
69 return ret;
70}
71
72}
73}
74
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
#define DBG
Definition: Logger.h:78
Base class for Exception.
Definition: Exception.h:146
const std::string & asString() const
String representation.
Definition: Pathname.h:91
virtual bool isDesiredMedia(const media::MediaAccessRef &ref)
Check if it is the desider media.
SUSEMediaVerifier(const std::string &vendor_r, const std::string &id_r, const media::MediaNr media_nr=1)
create a verifier from attributes
String related utilities and Regular expression matching.
std::string getline(std::istream &str)
Read one line from stream.
Definition: IOStream.cc:33
unsigned int MediaNr
Definition: MediaManager.h:40
std::string numstring(char n, int w=0)
Definition: String.h:286
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:286