libzypp  13.10.6
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 
30 namespace zypp {
31  namespace media {
32 
33 
35 //
36 // CLASS NAME : MediaHandler
45 class MediaHandler {
46  friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
47 
48  public:
49  typedef shared_ptr<MediaHandler> Ptr;
50  typedef shared_ptr<const MediaHandler> constPtr;
51 
52  static bool setAttachPrefix(const Pathname &attach_prefix);
53 
54  static std::string getRealPath(const std::string &path);
55  static Pathname getRealPath(const Pathname &path);
56 
57  private:
61  static Pathname _attachPrefix;
62 
66  mutable
68 
74 
86 
92  Pathname _relativeRoot;
93 
99 
101  mutable time_t _attach_mtime;
102 
104  mutable Pathname _deltafile;
105 
106  protected:
110  const Url _url;
111 
116 
124  friend class MediaAccess;
125 
132  bool dependsOnParent(MediaAccessId parentId,
133  bool exactIdMatch);
134  bool dependsOnParent();
135 
141  void resetParentId();
142 
146  Pathname attachPoint() const;
147 
153  void setAttachPoint(const Pathname &path, bool temp);
154 
159  void setAttachPoint(const AttachPointRef &ref);
160 
165 
171  void attachPointHint(const Pathname &path, bool temp);
172 
179  Pathname createAttachPoint() const;
186  Pathname createAttachPoint(const Pathname &attach_root) const;
187 
192  void removeAttachPoint();
193 
200  virtual bool checkAttachPoint(const Pathname &apoint) const;
201 
210  static bool checkAttachPoint(const Pathname &apoint,
211  bool empty_dir,
212  bool writeable);
213 
222  bool isUseableAttachPoint(const Pathname &path,
223  bool mtab=true) const;
224 
229  std::string mediaSourceName() const
230  {
231  return _mediaSource ? _mediaSource->name : "";
232  }
233 
238  void setMediaSource(const MediaSourceRef &ref);
239 
245  findAttachedMedia(const MediaSourceRef &media) const;
246 
259 
264  bool isSharedMedia() const;
265 
274  bool checkAttached(bool matchMountFs) const;
275 
284  void forceRelaseAllMedia(bool matchMountFs);
285  void forceRelaseAllMedia(const MediaSourceRef &ref,
286  bool matchMountFs);
287 
288  protected:
289 
291  //
292  // Real action interface to be overloaded by concrete handler.
293  //
295 
308  virtual void attachTo(bool next = false) = 0;
309 
325  virtual void disconnectFrom() { return; }
326 
339  virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
340 
347  virtual void forceEject( const std::string & device ) {}
348 
360  virtual void getFile( const Pathname & filename ) const = 0;
361 
373  virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename ) const;
374 
375 
391  virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
392 
408  virtual void getDirInfo( std::list<std::string> & retlist,
409  const Pathname & dirname, bool dots = true ) const = 0;
410 
422  virtual void getDirInfo( filesystem::DirContent & retlist,
423  const Pathname & dirname, bool dots = true ) const = 0;
424 
433  virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
434 
435  protected:
436 
445  void getDirectoryYast( std::list<std::string> & retlist,
446  const Pathname & dirname, bool dots = true ) const;
447 
457  const Pathname & dirname, bool dots = true ) const;
458 
459  public:
460 
472  MediaHandler ( const Url& url_r,
473  const Pathname & attach_point_r,
474  const Pathname & urlpath_below_attachpoint_r,
475  const bool does_download_r );
476 
481  virtual ~MediaHandler();
482 
483  public:
484 
485 
487  //
488  // MediaAccess interface. Does common checks and logging.
489  // Invokes real action if necessary.
490  //
492 
496  bool downloads() const { return _does_download; }
497 
501  std::string protocol() const { return _url.getScheme(); }
502 
506  Url url() const { return _url; }
507 
518  void attach(bool next);
519 
523  virtual bool isAttached() const { return _mediaSource != nullptr; }
524 
533  Pathname localRoot() const;
534 
540  Pathname localPath( const Pathname & pathname ) const;
541 
555  void disconnect();
556 
563  void release( const std::string & ejectDev = "" );
564 
573  void provideFile( Pathname filename ) const;
574 
586  void provideFileCopy( Pathname srcFilename, Pathname targetFilename) const;
587 
597  void provideDir( Pathname dirname ) const;
598 
608  void provideDirTree( Pathname dirname ) const;
609 
617  void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
618 
626  void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
627 
640  void releasePath( Pathname pathname ) const;
641 
642  /*
643  * set a deltafile to be used in the next download
644  */
645  void setDeltafile( const Pathname &filename = Pathname()) const;
646 
647  /*
648  * return the deltafile set with setDeltafile()
649  */
650  Pathname deltafile () const;
651 
652  public:
653 
667  void dirInfo( std::list<std::string> & retlist,
668  const Pathname & dirname, bool dots = true ) const;
669 
682  void dirInfo( filesystem::DirContent & retlist,
683  const Pathname & dirname, bool dots = true ) const;
684 
693  bool doesFileExist( const Pathname & filename ) const;
694 
698  virtual bool hasMoreDevices();
699 
708  virtual void
709  getDetectedDevices(std::vector<std::string> & devices,
710  unsigned int & index) const;
711 };
712 
714 
715  } // namespace media
716 } // namespace zypp
717 
718 
719 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
720 
721 
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...
void provideFile(Pathname filename) const
Use concrete handler to provide file denoted by path below &#39;localRoot&#39;.
bool isSharedMedia() const
Returns a hint if the media is shared or not.
virtual void getDir(const Pathname &dirname, bool recurse_r) const =0
Call concrete handler to provide directory content (not recursive!) below attach point.
Handle access to a medium.
Definition: MediaAccess.h:50
Pathname _relativeRoot
The relative root directory of the data on the media.
Definition: MediaHandler.h:92
bool downloads() const
Hint if files are downloaded or not.
Definition: MediaHandler.h:496
static std::string getRealPath(const std::string &path)
bool doesFileExist(const Pathname &filename) const
check if a file exists
static Pathname _attachPrefix
User defined default attach point prefix.
Definition: MediaHandler.h:61
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
virtual void disconnectFrom()
Call concrete handler to disconnect media.
Definition: MediaHandler.h:325
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
Pathname _deltafile
file usable for delta downloads
Definition: MediaHandler.h:104
void provideDirTree(Pathname dirname) const
Use concrete handler to provide directory tree denoted by path below &#39;localRoot&#39; (recursive!!).
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
virtual void getFileCopy(const Pathname &srcFilename, const Pathname &targetFilename) const
Call concrete handler to provide a file under a different place in the file system (usually not under...
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.
void releaseDir(const Pathname &dirname) const
Remove directory tree below localRoot IFF handler downloads files to the local filesystem.
Definition: MediaHandler.h:626
void dirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Return content of directory on media via retlist.
Pathname deltafile() const
MediaSourceRef _mediaSource
The attached media source description reference.
Definition: MediaHandler.h:67
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Ask the media manager if specified media source is already attached.
AttachedMedia attachedMedia() const
Returns the attached media.
Abstract base class for &#39;physical&#39; MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
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:110
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.
Provides API related macros.
virtual ~MediaHandler()
Contolling MediaAccess takes care, that attached media is released prior to deleting this...
static bool setAttachPrefix(const Pathname &attach_prefix)
void setDeltafile(const Pathname &filename=Pathname()) const
void releasePath(Pathname pathname) const
Remove pathname below localRoot IFF handler downloads files to the local filesystem.
void provideFileCopy(Pathname srcFilename, Pathname targetFilename) const
Call concrete handler to provide a copy of a file under a different place in the file system (usually...
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:544
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
Pathname localPath(const Pathname &pathname) const
Files provided will be available at &#39;localPath(filename)&#39;.
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...
virtual bool isAttached() const
True if media is attached.
Definition: MediaHandler.h:523
void getDirectoryYast(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Retrieve and if available scan dirname/directory.yast.
void removeAttachPoint()
Remove unused attach point.
AttachPoint _AttachPointHint
The user provided attach preferred point.
Definition: MediaHandler.h:85
virtual void forceEject(const std::string &device)
Call concrete handler to physically eject the media (i.e.
Definition: MediaHandler.h:347
AttachPoint attachPointHint() const
Get the actual attach point hint.
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
Pathname attachPoint() const
Return the currently used attach point.
MediaAccessId _parentId
Access Id of media handler we depend on.
Definition: MediaHandler.h:115
virtual void getFile(const Pathname &filename) const =0
Call concrete handler to provide file below attach point.
AttachPointRef _attachPoint
This is where the media will be actually attached (&quot;mounted&quot;).
Definition: MediaHandler.h:73
time_t _attach_mtime
timestamp of the the last attach verification
Definition: MediaHandler.h:101
std::string protocol() const
Protocol hint for MediaAccess.
Definition: MediaHandler.h:501
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not...
shared_ptr< MediaHandler > Ptr
Definition: MediaHandler.h:49
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
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:53
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:527
void releaseFile(const Pathname &filename) const
Remove filename below localRoot IFF handler downloads files to the local filesystem.
Definition: MediaHandler.h:617
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
void provideDir(Pathname dirname) const
Use concrete handler to provide directory denoted by path below &#39;localRoot&#39; (not recursive!).
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
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 ...
Url url() const
Url used.
Definition: MediaHandler.h:506
bool _does_download
True if concrete handler downloads files to the local filesystem.
Definition: MediaHandler.h:98
shared_ptr< const MediaHandler > constPtr
Definition: MediaHandler.h:50
Url manipulation class.
Definition: Url.h:87
std::string mediaSourceName() const
Get the media source name or an empty string.
Definition: MediaHandler.h:229