libzypp: zypp/media/MediaHandler.h Source File

libzypp 17.36.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>
27#include <zypp-media/MediaException>
28#include <zypp-core/Globals.h>
29#include <zypp-core/OnMediaLocation>
30
31#undef ZYPP_BASE_LOGGER_LOGGROUP
32#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::media"
33
34namespace zypp {
35 namespace media {
36
37 class MediaManager;
38
39
41//
42// CLASS NAME : MediaHandler
51 class MediaHandler {
52 friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
53
54 public:
55 using Ptr = shared_ptr<MediaHandler>;
56 using constPtr = shared_ptr<const MediaHandler>;
57
58 static bool setAttachPrefix(const Pathname &attach_prefix);
59
60 static std::string getRealPath(const std::string &path);
61 static Pathname getRealPath(const Pathname &path);
62
63 private:
67 static Pathname _attachPrefix;
68
72 mutable
73 MediaSourceRef _mediaSource;
74
79 AttachPointRef _attachPoint;
80
91 AttachPoint _attachPointHint;
92
98 Pathname _relativeRoot;
99
104 bool _does_download;
105
107 mutable time_t _attach_mtime;
108
109 protected:
113 const Url _url;
114
118 MediaAccessId _parentId;
119
120 public:
121
128 bool dependsOnParent(MediaAccessId parentId,
129 bool exactIdMatch);
130 bool dependsOnParent();
131
137 void resetParentId();
138
142 Pathname attachPoint() const;
143
149 void setAttachPoint(const Pathname &path, bool temp);
150
155 void setAttachPoint(const AttachPointRef &ref);
156
160 AttachPoint attachPointHint() const;
161
167 void attachPointHint(const Pathname &path, bool temp);
168
176 Pathname createAttachPoint() const;
183 Pathname createAttachPoint(const Pathname &attach_root) const;
184
189 void removeAttachPoint();
190
197 virtual bool checkAttachPoint(const Pathname &apoint) const;
198
207 static bool checkAttachPoint(const Pathname &apoint,
208 bool empty_dir,
209 bool writeable);
210
219 bool isUseableAttachPoint(const Pathname &path,
220 bool mtab=true) const;
221
226 std::string mediaSourceName() const
227 {
228 return _mediaSource ? _mediaSource->name : "";
229 }
230
235 void setMediaSource(const MediaSourceRef &ref);
236
241 AttachedMedia
242 findAttachedMedia(const MediaSourceRef &media) const;
243
255 AttachedMedia attachedMedia() const;
256
261 bool isSharedMedia() const;
262
271 bool checkAttached(bool matchMountFs) const;
272
281 void forceRelaseAllMedia(bool matchMountFs);
282 void forceRelaseAllMedia(const MediaSourceRef &ref,
283 bool matchMountFs);
284
285 protected:
286
288 //
289 // Real action interface to be overloaded by concrete handler.
290 //
292
305 virtual void attachTo(bool next = false) = 0;
306
322 virtual void disconnectFrom() { return; }
323
336 virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
337
344 virtual void forceEject( const std::string & device ) {}
345
357 virtual void getFile( const OnMediaLocation &file ) const;
358
370 virtual void getFileCopy( const OnMediaLocation & file, const Pathname & targetFilename ) const;
371
372
388 virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
389
405 virtual void getDirInfo( std::list<std::string> & retlist,
406 const Pathname & dirname, bool dots = true ) const = 0;
407
419 virtual void getDirInfo( filesystem::DirContent & retlist,
420 const Pathname & dirname, bool dots = true ) const = 0;
421
430 virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
431
432 protected:
433
442 void getDirectoryYast( std::list<std::string> & retlist,
443 const Pathname & dirname, bool dots = true ) const;
444
453 void getDirectoryYast( filesystem::DirContent & retlist,
454 const Pathname & dirname, bool dots = true ) const;
455
456 public:
457
469 MediaHandler ( Url url_r,
470 const Pathname & attach_point_r,
471 Pathname urlpath_below_attachpoint_r,
472 const bool does_download_r );
473
478 virtual ~MediaHandler();
479
480 public:
481
482
484 //
485 // MediaAccess interface. Does common checks and logging.
486 // Invokes real action if necessary.
487 //
489
493 bool downloads() const { return _does_download; }
494
498 std::string protocol() const { return _url.getScheme(); }
499
503 Url url() const { return _url; }
504
515 void attach(bool next);
516
520 virtual bool isAttached() const { return _mediaSource != nullptr; }
521
530 Pathname localRoot() const;
531
537 Pathname localPath( const Pathname & pathname ) const;
538
552 void disconnect();
553
560 void release( const std::string & ejectDev = "" );
561
570 void provideFile( const OnMediaLocation &file ) const;
571
583 void provideFileCopy( const OnMediaLocation &srcFile, const Pathname& targetFilename ) const;
584
594 void provideDir( const Pathname& dirname ) const;
595
605 void provideDirTree( const Pathname& dirname ) const;
606
614 void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
615
623 void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
624
637 void releasePath( const Pathname& pathname ) const;
638
639 public:
640
654 void dirInfo( std::list<std::string> & retlist,
655 const Pathname & dirname, bool dots = true ) const;
656
669 void dirInfo( filesystem::DirContent & retlist,
670 const Pathname & dirname, bool dots = true ) const;
671
680 bool doesFileExist( const Pathname & filename ) const;
681
685 virtual bool hasMoreDevices();
686
695 virtual void
696 getDetectedDevices(std::vector<std::string> & devices,
697 unsigned int & index) const;
698
709 virtual void
710 precacheFiles ( const std::vector< OnMediaLocation > &files );
711};
712
714
715 } // namespace media
716} // namespace zypp
717
718
719#endif // ZYPP_MEDIA_MEDIAHANDLERL_H
MediaSource.h
shared_ptr
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition onmedialocation.h:37
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::media::AttachPoint
Attach point of a media source.
Definition MediaSource.h:107
zypp::media::MediaHandler::isUseableAttachPoint
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...
Definition MediaHandler.cc:416
zypp::media::MediaHandler::getFile
virtual void getFile(const OnMediaLocation &file) const
Call concrete handler to provide file below attach point.
Definition MediaHandler.cc:1188
zypp::media::MediaHandler::attachTo
virtual void attachTo(bool next=false)=0
Call concrete handler to attach the media.
zypp::media::MediaHandler::url
Url url() const
Url used.
Definition MediaHandler.h:503
zypp::media::MediaHandler::provideDirTree
void provideDirTree(const Pathname &dirname) const
Use concrete handler to provide directory tree denoted by path below 'localRoot' (recursive!
Definition MediaHandler.cc:1008
zypp::media::MediaHandler::getDoesFileExist
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
Definition MediaHandler.cc:1326
zypp::media::MediaHandler::getDetectedDevices
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 ...
Definition MediaHandler.cc:1340
zypp::media::MediaHandler::checkAttachPoint
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
Definition MediaHandler.cc:848
zypp::media::MediaHandler::disconnect
void disconnect()
Use concrete handler to isconnect media.
Definition MediaHandler.cc:687
zypp::media::MediaHandler::_mediaSource
MediaSourceRef _mediaSource
The attached media source description reference.
Definition MediaHandler.h:73
zypp::media::MediaHandler::constPtr
shared_ptr< const MediaHandler > constPtr
Definition MediaHandler.h:56
zypp::media::MediaHandler::attach
void attach(bool next)
Use concrete handler to attach the media.
Definition MediaHandler.cc:633
zypp::media::MediaHandler::resetParentId
void resetParentId()
Called in case, where the media manager takes over the destruction of the parent id (e....
Definition MediaHandler.cc:116
zypp::media::MediaHandler::_attach_mtime
time_t _attach_mtime
timestamp of the the last attach verification
Definition MediaHandler.h:107
zypp::media::MediaHandler::precacheFiles
virtual void precacheFiles(const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
Definition MediaHandler.cc:1351
zypp::media::MediaHandler::isAttached
virtual bool isAttached() const
True if media is attached.
Definition MediaHandler.h:520
zypp::media::MediaHandler::hasMoreDevices
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
Definition MediaHandler.cc:1335
zypp::media::MediaHandler::_attachPointHint
AttachPoint _attachPointHint
The user provided attach preferred point.
Definition MediaHandler.h:91
zypp::media::MediaHandler::disconnectFrom
virtual void disconnectFrom()
Call concrete handler to disconnect media.
Definition MediaHandler.h:322
zypp::media::MediaHandler::getRealPath
static std::string getRealPath(const std::string &path)
Definition MediaHandler.cc:122
zypp::media::MediaHandler::downloads
bool downloads() const
Hint if files are downloaded or not.
Definition MediaHandler.h:493
zypp::media::MediaHandler::dirInfo
void dirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Return content of directory on media via retlist.
Definition MediaHandler.cc:1053
zypp::media::MediaHandler::createAttachPoint
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
Definition MediaHandler.cc:312
zypp::media::MediaHandler::_attachPoint
AttachPointRef _attachPoint
This is where the media will be actually attached ("mounted").
Definition MediaHandler.h:79
zypp::media::MediaHandler::attachPointHint
AttachPoint attachPointHint() const
Get the actual attach point hint.
Definition MediaHandler.cc:255
zypp::media::MediaHandler::releaseDir
void releaseDir(const Pathname &dirname) const
Remove directory tree below localRoot IFF handler downloads files to the local filesystem.
Definition MediaHandler.h:623
zypp::media::MediaHandler::MediaHandler
MediaHandler(Url url_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
zypp::media::MediaHandler::doesFileExist
bool doesFileExist(const Pathname &filename) const
check if a file exists
Definition MediaHandler.cc:1097
zypp::media::MediaHandler::setAttachPrefix
static bool setAttachPrefix(const Pathname &attach_prefix)
Definition MediaHandler.cc:283
zypp::media::MediaHandler::Ptr
shared_ptr< MediaHandler > Ptr
Definition MediaHandler.h:55
zypp::media::MediaHandler::mediaSourceName
std::string mediaSourceName() const
Get the media source name or an empty string.
Definition MediaHandler.h:226
zypp::media::MediaHandler::getFileCopy
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...
Definition MediaHandler.cc:1201
zypp::media::MediaHandler::setMediaSource
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Definition MediaHandler.cc:432
zypp::media::MediaHandler::localPath
Pathname localPath(const Pathname &pathname) const
Files provided will be available at 'localPath(filename)'.
Definition MediaHandler.cc:664
zypp::media::MediaHandler::_attachPrefix
static Pathname _attachPrefix
User defined default attach point prefix.
Definition MediaHandler.h:67
zypp::media::MediaHandler::protocol
std::string protocol() const
Protocol hint for MediaAccess.
Definition MediaHandler.h:498
zypp::media::MediaHandler::operator<<
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Definition MediaHandler.cc:1181
zypp::media::MediaHandler::forceRelaseAllMedia
void forceRelaseAllMedia(bool matchMountFs)
Call to this function will try to release all media matching the currenlty attached media source,...
Definition MediaHandler.cc:778
zypp::media::MediaHandler::_url
const Url _url
Url to handle.
Definition MediaHandler.h:113
zypp::media::MediaHandler::release
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition MediaHandler.cc:704
zypp::media::MediaHandler::checkAttached
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
Definition MediaHandler.cc:479
zypp::media::MediaHandler::removeAttachPoint
void removeAttachPoint()
Remove unused attach point.
Definition MediaHandler.cc:143
zypp::media::MediaHandler::getDirectoryYast
void getDirectoryYast(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Retrieve and if available scan dirname/directory.yast.
Definition MediaHandler.cc:1114
zypp::media::MediaHandler::setAttachPoint
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Definition MediaHandler.cc:200
zypp::media::MediaHandler::attachPoint
Pathname attachPoint() const
Return the currently used attach point.
Definition MediaHandler.cc:185
zypp::media::MediaHandler::releaseFile
void releaseFile(const Pathname &filename) const
Remove filename below localRoot IFF handler downloads files to the local filesystem.
Definition MediaHandler.h:614
zypp::media::MediaHandler::localRoot
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not.
Definition MediaHandler.cc:206
zypp::media::MediaHandler::dependsOnParent
bool dependsOnParent()
Definition MediaHandler.cc:922
zypp::media::MediaHandler::~MediaHandler
virtual ~MediaHandler()
Contolling MediaAccess takes care, that attached media is released prior to deleting this.
Definition MediaHandler.cc:106
zypp::media::MediaHandler::getDir
virtual void getDir(const Pathname &dirname, bool recurse_r) const =0
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition MediaHandler.cc:1219
zypp::media::MediaHandler::_relativeRoot
Pathname _relativeRoot
The relative root directory of the data on the media.
Definition MediaHandler.h:98
zypp::media::MediaHandler::findAttachedMedia
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Ask the media manager if specified media source is already attached.
Definition MediaHandler.cc:269
zypp::media::MediaHandler::provideDir
void provideDir(const Pathname &dirname) const
Use concrete handler to provide directory denoted by path below 'localRoot' (not recursive!...
Definition MediaHandler.cc:989
zypp::media::MediaHandler::isSharedMedia
bool isSharedMedia() const
Returns a hint if the media is shared or not.
Definition MediaHandler.cc:465
zypp::media::MediaHandler::provideFileCopy
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...
Definition MediaHandler.cc:957
zypp::media::MediaHandler::releaseFrom
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
zypp::media::MediaHandler::provideFile
void provideFile(const OnMediaLocation &file) const
Use concrete handler to provide file denoted by path below 'localRoot'.
Definition MediaHandler.cc:969
zypp::media::MediaHandler::attachedMedia
AttachedMedia attachedMedia() const
Returns the attached media.
Definition MediaHandler.cc:448
zypp::media::MediaHandler::releasePath
void releasePath(const Pathname &pathname) const
Remove pathname below localRoot IFF handler downloads files to the local filesystem.
Definition MediaHandler.cc:1027
zypp::media::MediaHandler::forceEject
virtual void forceEject(const std::string &device)
Call concrete handler to physically eject the media (i.e.
Definition MediaHandler.h:344
zypp::media::MediaHandler::_does_download
bool _does_download
True if concrete handler downloads files to the local filesystem.
Definition MediaHandler.h:104
zypp::media::MediaHandler::getDirInfo
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.
Definition MediaHandler.cc:1241
zypp::media::MediaHandler::_parentId
MediaAccessId _parentId
Access Id of media handler we depend on.
Definition MediaHandler.h:118
str
String related utilities and Regular expression matching.
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition PathInfo.h:526
zypp::media
Definition MediaCD.cc:47
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition MediaSource.h:30
zypp::media::MediaSourceRef
zypp::RW_pointer< MediaSource > MediaSourceRef
Definition MediaSource.h:125
zypp::media::AttachPointRef
zypp::RW_pointer< AttachPoint > AttachPointRef
Definition MediaSource.h:126
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::media::AttachedMedia
A simple structure containing references to a media source and its attach point.
Definition MediaSource.h:135
Globals.h
Provides API related macros.
PathInfo.h
Pathname.h
Url.h
PtrTypes.h