libzypp 17.37.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 <any>
17#include <iosfwd>
18#include <string>
19#include <list>
20
21#include <zypp/Pathname.h>
22#include <zypp/PathInfo.h>
23#include <zypp/base/PtrTypes.h>
24
25#include <zypp/media/MediaUrl.h>
26
28#include <zypp-media/MediaException>
29#include <zypp-core/Globals.h>
30#include <zypp-core/OnMediaLocation>
31
32#undef ZYPP_BASE_LOGGER_LOGGROUP
33#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::media"
34
35namespace zypp {
36 namespace media {
37
38 class MediaManager;
39
41//
42// CLASS NAME : MediaHandler
52 friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
53
54 public:
57 static bool setAttachPrefix(const Pathname &attach_prefix);
58
59 static std::string getRealPath(const std::string &path);
60 static Pathname getRealPath(const Pathname &path);
61
62 private:
67
71 mutable
73
79
91
98
104
106 mutable time_t _attach_mtime;
107
108 protected:
109
113 const std::vector<MediaUrl> _urls;
114
118 const MediaUrl _url;
119
124
125 public:
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
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
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 OnMediaLocation &file ) const;
363
375 virtual void getFileCopy( const OnMediaLocation & file, const Pathname & targetFilename ) const;
376
377
393 virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
394
410 virtual void getDirInfo( std::list<std::string> & retlist,
411 const Pathname & dirname, bool dots = true ) const = 0;
412
424 virtual void getDirInfo( filesystem::DirContent & retlist,
425 const Pathname & dirname, bool dots = true ) const = 0;
426
435 virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
436
437 protected:
438
447 void getDirectoryYast( std::list<std::string> & retlist,
448 const Pathname & dirname, bool dots = true ) const;
449
459 const Pathname & dirname, bool dots = true ) const;
460
461 public:
462
474 MediaHandler ( MediaUrl primaryUrl_r,
475 std::vector<MediaUrl> urls_r,
476 const Pathname & attach_point_r,
477 Pathname urlpath_below_attachpoint_r,
478 const bool does_download_r );
479
484 virtual ~MediaHandler();
485
486 public:
487
488
490 //
491 // MediaAccess interface. Does common checks and logging.
492 // Invokes real action if necessary.
493 //
495
499 bool downloads() const { return _does_download; }
500
504 std::string protocol() const { return _url.url().getScheme(); }
505
509 Url url() const { return _url.url(); }
510
521 void attach(bool next);
522
526 virtual bool isAttached() const { return _mediaSource != nullptr; }
527
536 Pathname localRoot() const;
537
543 Pathname localPath( const Pathname & pathname ) const;
544
558 void disconnect();
559
566 void release( const std::string & ejectDev = "" );
567
576 void provideFile( const OnMediaLocation &file ) const;
577
589 void provideFileCopy( const OnMediaLocation &srcFile, const Pathname& targetFilename ) const;
590
600 void provideDir( const Pathname& dirname ) const;
601
611 void provideDirTree( const Pathname& dirname ) const;
612
620 void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
621
629 void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
630
643 void releasePath( const Pathname& pathname ) const;
644
645 public:
646
660 void dirInfo( std::list<std::string> & retlist,
661 const Pathname & dirname, bool dots = true ) const;
662
675 void dirInfo( filesystem::DirContent & retlist,
676 const Pathname & dirname, bool dots = true ) const;
677
686 bool doesFileExist( const Pathname & filename ) const;
687
691 virtual bool hasMoreDevices();
692
701 virtual void
702 getDetectedDevices(std::vector<std::string> & devices,
703 unsigned int & index) const;
704
715 virtual void
716 precacheFiles ( const std::vector< OnMediaLocation > &files );
717};
718
720
721 } // namespace media
722} // namespace zypp
723
724
725#endif // ZYPP_MEDIA_MEDIAHANDLERL_H
Describes a resource file located on a medium.
Url manipulation class.
Definition Url.h:93
Attach point of a media source.
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 void getFile(const OnMediaLocation &file) const
Call concrete handler to provide file below attach point.
virtual void attachTo(bool next=false)=0
Call concrete handler to attach the media.
Url url() const
Primary Url used.
void provideDirTree(const Pathname &dirname) const
Use concrete handler to provide directory tree denoted by path below 'localRoot' (recursive!
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
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 ...
const MediaUrl _url
Primary Url.
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
void disconnect()
Use concrete handler to isconnect media.
MediaSourceRef _mediaSource
The attached media source description reference.
shared_ptr< const MediaHandler > constPtr
void attach(bool next)
Use concrete handler to attach the media.
void resetParentId()
Called in case, where the media manager takes over the destruction of the parent id (e....
time_t _attach_mtime
timestamp of the the last attach verification
virtual void precacheFiles(const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
virtual bool isAttached() const
True if media is attached.
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
AttachPoint _attachPointHint
The user provided attach preferred point.
virtual void disconnectFrom()
Call concrete handler to disconnect media.
static std::string getRealPath(const std::string &path)
bool downloads() const
Hint if files are downloaded or not.
void dirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Return content of directory on media via retlist.
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
AttachPointRef _attachPoint
This is where the media will be actually attached ("mounted").
AttachPoint attachPointHint() const
Get the actual attach point hint.
void releaseDir(const Pathname &dirname) const
Remove directory tree below localRoot IFF handler downloads files to the local filesystem.
bool doesFileExist(const Pathname &filename) const
check if a file exists
static bool setAttachPrefix(const Pathname &attach_prefix)
shared_ptr< MediaHandler > Ptr
MediaHandler(MediaUrl primaryUrl_r, std::vector< MediaUrl > urls_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.
std::string mediaSourceName() const
Get the media source name or an empty string.
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 setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Pathname localPath(const Pathname &pathname) const
Files provided will be available at 'localPath(filename)'.
static Pathname _attachPrefix
User defined default attach point prefix.
std::string protocol() const
Protocol hint for MediaAccess.
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
void forceRelaseAllMedia(bool matchMountFs)
Call to this function will try to release all media matching the currenlty attached media source,...
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
void removeAttachPoint()
Remove unused attach point.
void getDirectoryYast(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Retrieve and if available scan dirname/directory.yast.
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Pathname attachPoint() const
Return the currently used attach point.
void releaseFile(const Pathname &filename) const
Remove filename below localRoot IFF handler downloads files to the local filesystem.
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not.
virtual ~MediaHandler()
Contolling MediaAccess takes care, that attached media is released prior to deleting this.
const std::vector< MediaUrl > _urls
All mirrors including the primary.
virtual void getDir(const Pathname &dirname, bool recurse_r) const =0
Call concrete handler to provide directory content (not recursive!) below attach point.
Pathname _relativeRoot
The relative root directory of the data on the media.
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Ask the media manager if specified media source is already attached.
void provideDir(const Pathname &dirname) const
Use concrete handler to provide directory denoted by path below 'localRoot' (not recursive!...
bool isSharedMedia() const
Returns a hint if the media is shared or not.
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...
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
void provideFile(const OnMediaLocation &file) const
Use concrete handler to provide file denoted by path below 'localRoot'.
AttachedMedia attachedMedia() const
Returns the attached media.
void releasePath(const Pathname &pathname) const
Remove pathname below localRoot IFF handler downloads files to the local filesystem.
virtual void forceEject(const std::string &device)
Call concrete handler to physically eject the media (i.e.
bool _does_download
True if concrete handler downloads files to the local filesystem.
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.
MediaAccessId _parentId
Access Id of media handler we depend on.
String related utilities and Regular expression matching.
std::list< DirEntry > DirContent
Returned by readdir.
Definition PathInfo.h:526
unsigned int MediaAccessId
Media manager access Id type.
Definition MediaSource.h:30
zypp::RW_pointer< MediaSource > MediaSourceRef
zypp::RW_pointer< AttachPoint > AttachPointRef
Easy-to use interface to the ZYPP dependency resolver.
A simple structure containing references to a media source and its attach point.
Provides API related macros.