1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/MediaProducts.h
10 * Functions to find out products in media
12 #ifndef ZYPP_MEDIAPRODUCTS_H_
13 #define ZYPP_MEDIAPRODUCTS_H_
18 #include "zypp/ZConfig.h"
19 #include "zypp/base/Logger.h"
20 #include "zypp/media/MediaManager.h"
21 #include "zypp/base/UserRequestException.h"
23 #include "zypp/ProgressData.h"
28 * \short Represents an available product in media
30 struct MediaProductEntry
38 MediaProductEntry( const Pathname & dir_r = "/", const std::string & name_r = std::string() )
39 : _dir(dir_r), _name(name_r)
43 bool operator<( const MediaProductEntry &rhs ) const
45 int res = _name.compare( rhs._name );
46 return ( res < 0 || ( res == 0 && _dir < rhs._dir ) );
51 * A set of available products in media
53 typedef std::set<MediaProductEntry> MediaProductSet;
56 * FIXME: add a comment here...
58 template <class TOutputIterator>
59 static void scanProductsFile( const Pathname & file_r, TOutputIterator result )
61 std::ifstream pfile( file_r.asString().c_str() );
62 while ( pfile.good() ) {
64 std::string value = str::getline( pfile, str::TRIM );
66 ERR << "Error parsing " << file_r << std::endl;
67 ZYPP_THROW(Exception("Error parsing " + file_r.asString()));
70 break; // no data on last line
72 std::string tag = str::stripFirstWord( value, true );
75 *result = MediaProductEntry( tag, value );
81 * \short Available products in a url location
83 * \param url_r url to inspect
84 * \param result output iterator where \ref MediaProductEntry
85 * items will be inserted.
86 * \throws MediaException If accessng the media fails
88 template <class TOutputIterator>
89 void productsInMedia( const Url & url_r, TOutputIterator result )
91 media::MediaManager media_mgr;
93 media::MediaId id = media_mgr.open(url_r);
95 Pathname products_file = Pathname("media.1/products");
98 media_mgr.provideFile (id, products_file);
99 products_file = media_mgr.localPath (id, products_file);
100 scanProductsFile (products_file, result);
102 catch ( const Exception & excpt ) {
104 MIL << "No products description found on the Url" << std::endl;
106 media_mgr.release(id, "");
110 * \short Available products in a url location
112 * \param url_r url to inspect
113 * \param set ef MediaProductEntry set where
114 * items will be inserted.
115 * \throws MediaException If accessng the media fails
117 void productsInMedia( const Url & url_r, MediaProductSet &set )
119 productsInMedia(url_r, std::inserter(set, set.end()));
126 // vim: set ts=2 sts=2 sw=2 et ai: