libzypp  17.25.2
MediaHandler.h
Go to the documentation of this file.
1 
2 /*---------------------------------------------------------------------\
3 | ____ _ __ __ ___ |
4 | |__ / \ / / . \ . \ |
5 | / / \ V /| _/ _/ |
6 | / /__ | | | | | | |
7 | /_____||_| |_| |_| |
8 | |
9 \---------------------------------------------------------------------*/
13 #ifndef ZYPP_MEDIA_MEDIAHANDLERL_H
14 #define ZYPP_MEDIA_MEDIAHANDLERL_H
15 
16 #include <iosfwd>
17 #include <string>
18 #include <list>
19 
20 #include <zypp/Pathname.h>
21 #include <zypp/PathInfo.h>
22 #include <zypp/base/PtrTypes.h>
23 
24 #include <zypp/Url.h>
25 
26 #include <zypp/media/MediaSource.h>
28 #include <zypp/APIConfig.h>
29 #include <zypp/OnMediaLocation.h>
30 
31 namespace zypp {
32  namespace media {
33 
34 
36 //
37 // CLASS NAME : MediaHandler
46 class MediaHandler {
47  friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
48 
49  public:
50  typedef shared_ptr<MediaHandler> Ptr;
51  typedef shared_ptr<const MediaHandler> constPtr;
52 
53  static bool setAttachPrefix(const Pathname &attach_prefix);
54 
55  static std::string getRealPath(const std::string &path);
56  static Pathname getRealPath(const Pathname &path);
57 
58  private:
63 
67  mutable
69 
75 
87 
94 
100 
102  mutable time_t _attach_mtime;
103 
106 
107  protected:
111  const Url _url;
112 
117 
125  friend class MediaAccess;
126 
133  bool dependsOnParent(MediaAccessId parentId,
134  bool exactIdMatch);
135  bool dependsOnParent();
136 
142  void resetParentId();
143 
147  Pathname attachPoint() const;
148 
154  void setAttachPoint(const Pathname &path, bool temp);
155 
160  void setAttachPoint(const AttachPointRef &ref);
161 
166 
172  void attachPointHint(const Pathname &path, bool temp);
173 
181  Pathname createAttachPoint() const;
188  Pathname createAttachPoint(const Pathname &attach_root) const;
189 
194  void removeAttachPoint();
195 
202  virtual bool checkAttachPoint(const Pathname &apoint) const;
203 
212  static bool checkAttachPoint(const Pathname &apoint,
213  bool empty_dir,
214  bool writeable);
215 
224  bool isUseableAttachPoint(const Pathname &path,
225  bool mtab=true) const;
226 
231  std::string mediaSourceName() const
232  {
233  return _mediaSource ? _mediaSource->name : "";
234  }
235 
240  void setMediaSource(const MediaSourceRef &ref);
241 
247  findAttachedMedia(const MediaSourceRef &media) const;
248 
261 
266  bool isSharedMedia() const;
267 
276  bool checkAttached(bool matchMountFs) const;
277 
286  void forceRelaseAllMedia(bool matchMountFs);
287  void forceRelaseAllMedia(const MediaSourceRef &ref,
288  bool matchMountFs);
289 
290  protected:
291 
293  //
294  // Real action interface to be overloaded by concrete handler.
295  //
297 
310  virtual void attachTo(bool next = false) = 0;
311 
327  virtual void disconnectFrom() { return; }
328 
341  virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
342 
349  virtual void forceEject( const std::string & device ) {}
350 
362  virtual void getFile( const Pathname & filename, const ByteCount &expectedFileSize_r ) const;
363 
364 
375  virtual void getFiles( const std::vector< std::pair<Pathname, ByteCount> > &files ) const;
376 
388  virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, const ByteCount &expectedFileSize_r ) const;
389 
390 
406  virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
407 
423  virtual void getDirInfo( std::list<std::string> & retlist,
424  const Pathname & dirname, bool dots = true ) const = 0;
425 
437  virtual void getDirInfo( filesystem::DirContent & retlist,
438  const Pathname & dirname, bool dots = true ) const = 0;
439 
448  virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
449 
450  protected:
451 
460  void getDirectoryYast( std::list<std::string> & retlist,
461  const Pathname & dirname, bool dots = true ) const;
462 
472  const Pathname & dirname, bool dots = true ) const;
473 
474  public:
475 
487  MediaHandler ( const Url& url_r,
488  const Pathname & attach_point_r,
489  const Pathname & urlpath_below_attachpoint_r,
490  const bool does_download_r );
491 
496  virtual ~MediaHandler();
497 
498  public:
499 
500 
502  //
503  // MediaAccess interface. Does common checks and logging.
504  // Invokes real action if necessary.
505  //
507 
511  bool downloads() const { return _does_download; }
512 
516  std::string protocol() const { return _url.getScheme(); }
517 
521  Url url() const { return _url; }
522 
533  void attach(bool next);
534 
538  virtual bool isAttached() const { return _mediaSource != nullptr; }
539 
548  Pathname localRoot() const;
549 
555  Pathname localPath( const Pathname & pathname ) const;
556 
570  void disconnect();
571 
578  void release( const std::string & ejectDev = "" );
579 
588  void provideFile( Pathname filename, const ByteCount &expectedFileSize_r ) const;
589 
601  void provideFileCopy( Pathname srcFilename, Pathname targetFilename, const ByteCount &expectedFileSize_r ) const;
602 
612  void provideDir( Pathname dirname ) const;
613 
623  void provideDirTree( Pathname dirname ) const;
624 
632  void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
633 
641  void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
642 
655  void releasePath( Pathname pathname ) const;
656 
657  /*
658  * set a deltafile to be used in the next download
659  */
660  void setDeltafile( const Pathname &filename = Pathname()) const;
661 
662  /*
663  * return the deltafile set with setDeltafile()
664  */
665  Pathname deltafile () const;
666 
667  public:
668 
682  void dirInfo( std::list<std::string> & retlist,
683  const Pathname & dirname, bool dots = true ) const;
684 
697  void dirInfo( filesystem::DirContent & retlist,
698  const Pathname & dirname, bool dots = true ) const;
699 
708  bool doesFileExist( const Pathname & filename ) const;
709 
713  virtual bool hasMoreDevices();
714 
723  virtual void
724  getDetectedDevices(std::vector<std::string> & devices,
725  unsigned int & index) const;
726 
737  virtual void
738  precacheFiles ( const std::vector< OnMediaLocation > &files );
739 };
740 
742 
743  } // namespace media
744 } // namespace zypp
745 
746 
747 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
748 
749 
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:528
Attach point of a media source.
Definition: MediaSource.h:105
void resetParentId()
Called in case, where the media manager takes over the destruction of the parent id (e...
virtual void getDir(const Pathname &dirname, bool recurse_r) const =0
Call concrete handler to provide directory content (not recursive!) below attach point.
AttachPoint _attachPointHint
The user provided attach preferred point.
Definition: MediaHandler.h:86
Handle access to a medium.
Definition: MediaAccess.h:51
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
AttachedMedia attachedMedia() const
Returns the attached media.
Store and operate with byte count.
Definition: ByteCount.h:30
Pathname _relativeRoot
The relative root directory of the data on the media.
Definition: MediaHandler.h:93
Pathname deltafile() const
static std::string getRealPath(const std::string &path)
std::string protocol() const
Protocol hint for MediaAccess.
Definition: MediaHandler.h:516
static Pathname _attachPrefix
User defined default attach point prefix.
Definition: MediaHandler.h:62
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
void dirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Return content of directory on media via retlist.
virtual void disconnectFrom()
Call concrete handler to disconnect media.
Definition: MediaHandler.h:327
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Ask media manager, if the specified path is already used as attach point or if there are another atta...
String related utilities and Regular expression matching.
Pathname _deltafile
file usable for delta downloads
Definition: MediaHandler.h:105
void provideDir(Pathname dirname) const
Use concrete handler to provide directory denoted by path below &#39;localRoot&#39; (not recursive!).
void releasePath(Pathname pathname) const
Remove pathname below localRoot IFF handler downloads files to the local filesystem.
void setDeltafile(const Pathname &filename=Pathname()) const
bool doesFileExist(const Pathname &filename) const
check if a file exists
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
virtual void attachTo(bool next=false)=0
Call concrete handler to attach the media.
virtual void getFileCopy(const Pathname &srcFilename, const Pathname &targetFilename, const ByteCount &expectedFileSize_r) const
Call concrete handler to provide a file under a different place in the file system (usually not under...
Pathname localPath(const Pathname &pathname) const
Files provided will be available at &#39;localPath(filename)&#39;.
void releaseDir(const Pathname &dirname) const
Remove directory tree below localRoot IFF handler downloads files to the local filesystem.
Definition: MediaHandler.h:641
std::string mediaSourceName() const
Get the media source name or an empty string.
Definition: MediaHandler.h:231
MediaSourceRef _mediaSource
The attached media source description reference.
Definition: MediaHandler.h:68
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
virtual void getFiles(const std::vector< std::pair< Pathname, ByteCount > > &files) const
Call concrete handler to provide all files below attach point.
void provideDirTree(Pathname dirname) const
Use concrete handler to provide directory tree denoted by path below &#39;localRoot&#39; (recursive!!).
Abstract base class for &#39;physical&#39; MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:46
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:133
const Url _url
Url to handle.
Definition: MediaHandler.h:111
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
void disconnect()
Use concrete handler to isconnect media.
void attach(bool next)
Use concrete handler to attach the media.
bool isSharedMedia() const
Returns a hint if the media is shared or not.
virtual ~MediaHandler()
Contolling MediaAccess takes care, that attached media is released prior to deleting this...
static bool setAttachPrefix(const Pathname &attach_prefix)
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
void getDirectoryYast(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Retrieve and if available scan dirname/directory.yast.
AttachPoint attachPointHint() const
Get the actual attach point hint.
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
void provideFile(Pathname filename, const ByteCount &expectedFileSize_r) const
Use concrete handler to provide file denoted by path below &#39;localRoot&#39;.
void removeAttachPoint()
Remove unused attach point.
virtual void precacheFiles(const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not...
virtual void forceEject(const std::string &device)
Call concrete handler to physically eject the media (i.e.
Definition: MediaHandler.h:349
void forceRelaseAllMedia(bool matchMountFs)
Call to this function will try to release all media matching the currenlty attached media source...
virtual void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const =0
Call concrete handler to provide a content list of directory on media via retlist.
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Ask the media manager if specified media source is already attached.
void releaseFile(const Pathname &filename) const
Remove filename below localRoot IFF handler downloads files to the local filesystem.
Definition: MediaHandler.h:632
bool downloads() const
Hint if files are downloaded or not.
Definition: MediaHandler.h:511
Pathname attachPoint() const
Return the currently used attach point.
Url url() const
Url used.
Definition: MediaHandler.h:521
virtual void getDetectedDevices(std::vector< std::string > &devices, unsigned int &index) const
Fill in a vector of detected ejectable devices and the index of the currently attached device within ...
MediaAccessId _parentId
Access Id of media handler we depend on.
Definition: MediaHandler.h:116
AttachPointRef _attachPoint
This is where the media will be actually attached ("mounted").
Definition: MediaHandler.h:74
time_t _attach_mtime
timestamp of the the last attach verification
Definition: MediaHandler.h:102
shared_ptr< MediaHandler > Ptr
Definition: MediaHandler.h:50
virtual void getFile(const Pathname &filename, const ByteCount &expectedFileSize_r) const
Call concrete handler to provide file below attach point.
MediaHandler(const Url &url_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
If the concrete media handler provides a nonempty attach_point, it must be an existing directory...
Definition: MediaHandler.cc:54
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
virtual bool isAttached() const
True if media is attached.
Definition: MediaHandler.h:538
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
bool _does_download
True if concrete handler downloads files to the local filesystem.
Definition: MediaHandler.h:99
shared_ptr< const MediaHandler > constPtr
Definition: MediaHandler.h:51
Url manipulation class.
Definition: Url.h:87
void provideFileCopy(Pathname srcFilename, Pathname targetFilename, const ByteCount &expectedFileSize_r) const
Call concrete handler to provide a copy of a file under a different place in the file system (usually...