libzypp  17.25.2
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 #include <zypp/ManagedFile.h>
27 
29 namespace zypp
30 {
31 
33 
35  //
36  // CLASS NAME : MediaSetAccess
37  //
81  {
82  friend std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj );
83 
84  public:
92  MediaSetAccess( const Url &url, const Pathname & prefered_attach_point = "" );
94  MediaSetAccess( const std::string & label_r, const Url &url, const Pathname & prefered_attach_point = "" );
96 
100  void setVerifier( unsigned media_nr, media::MediaVerifierRef verifier );
101 
105  const std::string & label() const
106  { return _label; }
107 
111  void setLabel( const std::string & label_r )
112  { _label = label_r; }
113 
115  {
121  };
122  ZYPP_DECLARE_FLAGS(ProvideFileOptions,ProvideFileOption);
123 
134  void precacheFiles(const std::vector<OnMediaLocation> &files);
135 
163  Pathname provideFile( const OnMediaLocation & resource, ProvideFileOptions options = PROVIDE_DEFAULT, const Pathname &deltafile = Pathname() );
164 
185  Pathname provideFile(const Pathname & file, unsigned media_nr = 1, ProvideFileOptions options = PROVIDE_DEFAULT );
186 
194  Pathname provideOptionalFile( const Pathname & file, unsigned media_nr = 1 );
195 
213  static ManagedFile provideFileFromUrl( const Url & file_url, ProvideFileOptions options = PROVIDE_DEFAULT );
214 
222  static ManagedFile provideOptionalFileFromUrl( const Url & file_url );
223 
230  void releaseFile( const OnMediaLocation &resource );
231 
232 
240  void releaseFile(const Pathname & file, unsigned media_nr = 1 );
241 
258  {
261  ReleaseFileGuard( MediaSetAccess & media_r, const OnMediaLocation & loc_r )
262  : _media( media_r )
263  , _loc( loc_r )
264  {}
266  { _media.releaseFile( _loc ); }
267  private:
270  };
271 
289  Pathname provideDir(const Pathname & dir, bool recursive, unsigned media_nr = 1, ProvideFileOptions options = PROVIDE_DEFAULT );
290 
305  bool doesFileExist(const Pathname & file, unsigned media_nr = 1 );
306 
310  void dirInfo( filesystem::DirContent &retlist, const Pathname &dirname,
311  bool dots = true, unsigned media_nr = 1 );
312 
318  void release();
319 
334  static Url rewriteUrl (const Url & url_r, const media::MediaNr medianr);
335 
336  protected:
352  Pathname provideFileInternal( const OnMediaLocation &resource, ProvideFileOptions options );
353 
354  typedef function<void( media::MediaAccessId, const Pathname & )> ProvideOperation;
355 
356  void provide( ProvideOperation op, const OnMediaLocation &resource, ProvideFileOptions options, const Pathname &deltafile );
357 
359  virtual std::ostream & dumpOn( std::ostream & str ) const;
360 
361  private:
364 
372 
373  std::string _label;
374 
375  typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap;
376  typedef std::map<media::MediaNr, media::MediaVerifierRef > VerifierMap;
377 
382  };
384  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaSetAccess::ProvideFileOptions);
385 
387  inline std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj )
388  { return obj.dumpOn( str ); }
389 
390 
391 } // namespace zypp
393 #endif // ZYPP_SOURCE_MediaSetAccess_H
static ManagedFile provideOptionalFileFromUrl(const Url &file_url)
Provides an optional file from url.
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)
void precacheFiles(const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
Describes a resource file located on a medium.
static ManagedFile provideFileFromUrl(const Url &file_url, ProvideFileOptions options=PROVIDE_DEFAULT)
Provides file from url.
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.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(DiskUsageCounter::MountPoint::HintFlags)
String related utilities and Regular expression matching.
bool doesFileExist(const Pathname &file, unsigned media_nr=1)
Checks if a file exists on the specified media, with user callbacks.
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)
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)
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition: AutoDispose.h:92
const std::string & label() const
The label identifing this media set and to be sent in a media change request.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
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.
VerifierMap _verifiers
Mapping between media number and corespondent verifier.
Url manipulation class.
Definition: Url.h:87
unsigned int MediaNr
Definition: MediaManager.h:41
The user is not asked anything, and the error exception is just propagated.