libzypp  17.37.18
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 <any>
17 #include <iosfwd>
18 #include <string>
19 #include <list>
20 
21 #include <zypp-core/Pathname.h>
22 #include <zypp/PathInfo.h>
24 
25 #include <zypp/media/MediaSource.h>
26 #include <zypp-media/MediaException>
27 #include <zypp-core/Globals.h>
28 #include <zypp-core/OnMediaLocation>
30 
31 #undef ZYPP_BASE_LOGGER_LOGGROUP
32 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::media"
33 
34 namespace zypp {
35  namespace media {
36 
37  class MediaManager;
38 
40 //
41 // CLASS NAME : MediaHandler
50 class MediaHandler {
51  friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
52 
53  public:
54  using Ptr = shared_ptr<MediaHandler>;
55  using constPtr = shared_ptr<const MediaHandler>;
56  static bool setAttachPrefix(const Pathname &attach_prefix);
57 
58  static std::string getRealPath(const std::string &path);
59  static Pathname getRealPath(const Pathname &path);
60 
61  private:
66 
70  mutable
72 
78 
90 
97 
103 
105  mutable time_t _attach_mtime;
106 
107  protected:
108 
113 
118 
119  public:
120 
127  bool dependsOnParent(MediaAccessId parentId,
128  bool exactIdMatch);
129  bool dependsOnParent();
130 
136  void resetParentId();
137 
141  Pathname attachPoint() const;
142 
148  void setAttachPoint(const Pathname &path, bool temp);
149 
154  void setAttachPoint(const AttachPointRef &ref);
155 
160 
166  void attachPointHint(const Pathname &path, bool temp);
167 
175  Pathname createAttachPoint() const;
182  Pathname createAttachPoint(const Pathname &attach_root) const;
183 
188  void removeAttachPoint();
189 
196  virtual bool checkAttachPoint(const Pathname &apoint) const;
197 
206  static bool checkAttachPoint(const Pathname &apoint,
207  bool empty_dir,
208  bool writeable);
209 
218  bool isUseableAttachPoint(const Pathname &path,
219  bool mtab=true) const;
220 
225  std::string mediaSourceName() const
226  {
227  return _mediaSource ? _mediaSource->name : "";
228  }
229 
234  void setMediaSource(const MediaSourceRef &ref);
235 
241  findAttachedMedia(const MediaSourceRef &media) const;
242 
255 
260  bool isSharedMedia() const;
261 
270  bool checkAttached(bool matchMountFs) const;
271 
280  void forceRelaseAllMedia(bool matchMountFs);
281  void forceRelaseAllMedia(const MediaSourceRef &ref,
282  bool matchMountFs);
283 
284  protected:
285 
287  //
288  // Real action interface to be overloaded by concrete handler.
289  //
291 
304  virtual void attachTo(bool next = false) = 0;
305 
321  virtual void disconnectFrom() { return; }
322 
335  virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
336 
343  virtual void forceEject( const std::string & device ) {}
344 
356  virtual void getFile( const OnMediaLocation &file ) const;
357 
369  virtual void getFileCopy( const OnMediaLocation & file, const Pathname & targetFilename ) const;
370 
371 
387  virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
388 
404  virtual void getDirInfo( std::list<std::string> & retlist,
405  const Pathname & dirname, bool dots = true ) const = 0;
406 
418  virtual void getDirInfo( filesystem::DirContent & retlist,
419  const Pathname & dirname, bool dots = true ) const = 0;
420 
429  virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
430 
431  protected:
432 
441  void getDirectoryYast( std::list<std::string> & retlist,
442  const Pathname & dirname, bool dots = true ) const;
443 
453  const Pathname & dirname, bool dots = true ) const;
454 
455  public:
456 
468  MediaHandler ( MirroredOrigin origin_r,
469  const Pathname & attach_point_r,
470  Pathname urlpath_below_attachpoint_r,
471  const bool does_download_r );
472 
477  virtual ~MediaHandler();
478 
479  public:
480 
481 
483  //
484  // MediaAccess interface. Does common checks and logging.
485  // Invokes real action if necessary.
486  //
488 
492  bool downloads() const { return _does_download; }
493 
497  std::string protocol() const { return _origin.scheme(); }
498 
502  Url url() const { return _origin.authority().url(); }
503 
508 
519  void attach(bool next);
520 
524  virtual bool isAttached() const { return _mediaSource != nullptr; }
525 
534  Pathname localRoot() const;
535 
541  Pathname localPath( const Pathname & pathname ) const;
542 
556  void disconnect();
557 
564  void release( const std::string & ejectDev = "" );
565 
574  void provideFile( const OnMediaLocation &file ) const;
575 
587  void provideFileCopy( const OnMediaLocation &srcFile, const Pathname& targetFilename ) const;
588 
598  void provideDir( const Pathname& dirname ) const;
599 
609  void provideDirTree( const Pathname& dirname ) const;
610 
618  void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
619 
627  void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
628 
641  void releasePath( const Pathname& pathname ) const;
642 
643  public:
644 
658  void dirInfo( std::list<std::string> & retlist,
659  const Pathname & dirname, bool dots = true ) const;
660 
673  void dirInfo( filesystem::DirContent & retlist,
674  const Pathname & dirname, bool dots = true ) const;
675 
684  bool doesFileExist( const Pathname & filename ) const;
685 
689  virtual bool hasMoreDevices();
690 
699  virtual void
700  getDetectedDevices(std::vector<std::string> & devices,
701  unsigned int & index) const;
702 
713  virtual void
714  precacheFiles ( const std::vector< OnMediaLocation > &files );
715 };
716 
718 
719  } // namespace media
720 } // namespace zypp
721 
722 
723 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
Attach point of a media source.
Definition: MediaSource.h:106
void resetParentId()
Called in case, where the media manager takes over the destruction of the parent id (e...
void releasePath(const Pathname &pathname) const
Remove pathname below localRoot IFF handler downloads files to the local filesystem.
Describes a resource file located on a medium.
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:89
void provideDir(const Pathname &dirname) const
Use concrete handler to provide directory denoted by path below &#39;localRoot&#39; (not recursive!).
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.
OriginEndpoint originEndpoint() const
Primary OriginEndpoint used.
Definition: MediaHandler.h:507
Pathname _relativeRoot
The relative root directory of the data on the media.
Definition: MediaHandler.h:96
static std::string getRealPath(const std::string &path)
std::string protocol() const
Protocol hint for MediaAccess.
Definition: MediaHandler.h:497
static Pathname _attachPrefix
User defined default attach point prefix.
Definition: MediaHandler.h:65
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:321
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.
shared_ptr< const MediaHandler > constPtr
Definition: MediaHandler.h:55
void provideFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename) const
Call concrete handler to provide a copy of a file under a different place in the file system (usually...
const zypp::Url & url() const
void provideDirTree(const Pathname &dirname) const
Use concrete handler to provide directory tree denoted by path below &#39;localRoot&#39; (recursive!!).
bool doesFileExist(const Pathname &filename) const
check if a file exists
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:526
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
virtual void attachTo(bool next=false)=0
Call concrete handler to attach the media.
Pathname localPath(const Pathname &pathname) const
Files provided will be available at &#39;localPath(filename)&#39;.
virtual void getFileCopy(const OnMediaLocation &file, const Pathname &targetFilename) const
Call concrete handler to provide a file under a different place in the file system (usually not under...
void releaseDir(const Pathname &dirname) const
Remove directory tree below localRoot IFF handler downloads files to the local filesystem.
Definition: MediaHandler.h:627
std::string mediaSourceName() const
Get the media source name or an empty string.
Definition: MediaHandler.h:225
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:30
MediaSourceRef _mediaSource
The attached media source description reference.
Definition: MediaHandler.h:71
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
Abstract base class for &#39;physical&#39; MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:50
MirroredOrigin _origin
Contains the authority URL and mirrors.
Definition: MediaHandler.h:112
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:134
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
void provideFile(const OnMediaLocation &file) const
Use concrete handler to provide file denoted by path below &#39;localRoot&#39;.
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)
Provides API related macros.
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).
MediaHandler(MirroredOrigin origin_r, const Pathname &attach_point_r, 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:55
void removeAttachPoint()
Remove unused attach point.
std::string scheme() const
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:343
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:618
bool downloads() const
Hint if files are downloaded or not.
Definition: MediaHandler.h:492
Pathname attachPoint() const
Return the currently used attach point.
Url url() const
Primary Url used.
Definition: MediaHandler.h:502
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:117
AttachPointRef _attachPoint
This is where the media will be actually attached ("mounted").
Definition: MediaHandler.h:77
time_t _attach_mtime
timestamp of the the last attach verification
Definition: MediaHandler.h:105
shared_ptr< MediaHandler > Ptr
Definition: MediaHandler.h:54
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
virtual bool isAttached() const
True if media is attached.
Definition: MediaHandler.h:524
const OriginEndpoint & authority() const
Represents a single, configurable network endpoint, combining a URL with specific access settings...
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
virtual void getFile(const OnMediaLocation &file) const
Call concrete handler to provide file below attach point.
bool _does_download
True if concrete handler downloads files to the local filesystem.
Definition: MediaHandler.h:102
Url manipulation class.
Definition: Url.h:92