libzypp  16.22.5
MediaSetAccess.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #ifndef ZYPP_MediaSetAccess_H
11 #define ZYPP_MediaSetAccess_H
12 
13 #include <iosfwd>
14 #include <string>
15 #include <vector>
16 #include "zypp/base/Function.h"
17 
19 #include "zypp/base/NonCopyable.h"
20 #include "zypp/base/Flags.h"
21 #include "zypp/base/PtrTypes.h"
23 #include "zypp/Pathname.h"
24 #include "zypp/CheckSum.h"
25 #include "zypp/OnMediaLocation.h"
26 
28 namespace zypp
29 {
30 
31  DEFINE_PTR_TYPE(MediaSetAccess);
32 
34  //
35  // CLASS NAME : MediaSetAccess
36  //
80  {
81  friend std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj );
82 
83  public:
91  MediaSetAccess( const Url &url, const Pathname & prefered_attach_point = "" );
93  MediaSetAccess( const std::string & label_r, const Url &url, const Pathname & prefered_attach_point = "" );
95 
99  void setVerifier( unsigned media_nr, media::MediaVerifierRef verifier );
100 
104  const std::string & label() const
105  { return _label; }
106 
110  void setLabel( const std::string & label_r )
111  { _label = label_r; }
112 
114  {
120  };
121  ZYPP_DECLARE_FLAGS(ProvideFileOptions,ProvideFileOption);
122 
150  Pathname provideFile( const OnMediaLocation & resource, ProvideFileOptions options = PROVIDE_DEFAULT, const Pathname &deltafile = Pathname() );
151 
172  Pathname provideFile(const Pathname & file, unsigned media_nr = 1, ProvideFileOptions options = PROVIDE_DEFAULT );
173 
181  Pathname provideOptionalFile( const Pathname & file, unsigned media_nr = 1 );
182 
189  void releaseFile( const OnMediaLocation &resource );
190 
191 
199  void releaseFile(const Pathname & file, unsigned media_nr = 1 );
200 
217  {
220  ReleaseFileGuard( MediaSetAccess & media_r, const OnMediaLocation & loc_r )
221  : _media( media_r )
222  , _loc( loc_r )
223  {}
225  { _media.releaseFile( _loc ); }
226  private:
229  };
230 
248  Pathname provideDir(const Pathname & dir, bool recursive, unsigned media_nr = 1, ProvideFileOptions options = PROVIDE_DEFAULT );
249 
264  bool doesFileExist(const Pathname & file, unsigned media_nr = 1 );
265 
269  void dirInfo( filesystem::DirContent &retlist, const Pathname &dirname,
270  bool dots = true, unsigned media_nr = 1 );
271 
277  void release();
278 
293  static Url rewriteUrl (const Url & url_r, const media::MediaNr medianr);
294 
295  protected:
311  Pathname provideFileInternal( const OnMediaLocation &resource, ProvideFileOptions options );
312 
313  typedef function<void( media::MediaAccessId, const Pathname & )> ProvideOperation;
314 
315  void provide( ProvideOperation op, const OnMediaLocation &resource, ProvideFileOptions options, const Pathname &deltafile );
316 
318  virtual std::ostream & dumpOn( std::ostream & str ) const;
319 
320  private:
323 
331 
332  std::string _label;
333 
334  typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap;
335  typedef std::map<media::MediaNr, media::MediaVerifierRef > VerifierMap;
336 
341  };
343  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaSetAccess::ProvideFileOptions);
344 
346  inline std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj )
347  { return obj.dumpOn( str ); }
348 
349 
350 } // namespace zypp
352 #endif // ZYPP_SOURCE_MediaSetAccess_H
void setLabel(const std::string &label_r)
Set the label identifing this media set and to be sent in a media change request. ...
void provide(ProvideOperation op, const OnMediaLocation &resource, ProvideFileOptions options, const Pathname &deltafile)
Describes a path on a certain media amongs as the information required to download it...
MediaMap _medias
Mapping between media number and Media Access ID.
Url _url
Media or media set URL.
Pathname provideOptionalFile(const Pathname &file, unsigned media_nr=1)
Provides an optional file from media media_nr.
Pathname provideDir(const Pathname &dir, bool recursive, unsigned media_nr=1, ProvideFileOptions options=PROVIDE_DEFAULT)
Provides direcotry dir from media number media_nr.
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(DiskUsageCounter::MountPoint::HintFlags)
bool doesFileExist(const Pathname &file, unsigned media_nr=1)
Checks if a file exists on the specified media, with user callbacks.
Url url
Definition: MediaCurl.cc:207
Pathname _prefAttachPoint
Prefered mount point.
void release()
Release all attached media of this set.
static Url rewriteUrl(const Url &url_r, const media::MediaNr medianr)
Replaces media number in specified url with given medianr.
ZYPP_DECLARE_FLAGS(ProvideFileOptions, ProvideFileOption)
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
std::ostream & operator<<(std::ostream &str, const MediaSetAccess &obj)
std::map< media::MediaNr, media::MediaAccessId > MediaMap
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
void releaseFile(const OnMediaLocation &resource)
Release file from media.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
void dirInfo(filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true, unsigned media_nr=1)
Fills retlist with directory information.
DEFINE_PTR_TYPE(Application)
ReleaseFileGuard(MediaSetAccess &media_r, const OnMediaLocation &loc_r)
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
Base class for reference counted objects.
std::map< media::MediaNr, media::MediaVerifierRef > VerifierMap
function< void(media::MediaAccessId, const Pathname &)> ProvideOperation
Pathname provideFileInternal(const OnMediaLocation &resource, ProvideFileOptions options)
Provides the file from medium number media_nr and returns its local path.
void setVerifier(unsigned media_nr, media::MediaVerifierRef verifier)
Sets a MediaVerifier verifier for given media number.
MediaVerifierRef verifier
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:285
friend std::ostream & operator<<(std::ostream &str, const MediaSetAccess &obj)
media::MediaAccessId getMediaAccessId(media::MediaNr medianr)
Pathname provideFile(const OnMediaLocation &resource, ProvideFileOptions options=PROVIDE_DEFAULT, const Pathname &deltafile=Pathname())
Provides a file from a media location.
MediaSetAccess(const Url &url, const Pathname &prefered_attach_point="")
Creates a callback enabled media access for specified url.
const std::string & label() const
The label identifing this media set and to be sent in a media change request.
VerifierMap _verifiers
Mapping between media number and corespondent verifier.
Url manipulation class.
Definition: Url.h:87
Media access layer responsible for handling files distributed on a set of media with media change and...
unsigned int MediaNr
Definition: MediaManager.h:40
The user is not asked anything, and the error exception is just propagated.