libzypp 17.37.10

MediaDIR.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
13#include <iostream>
14
15#include <zypp/base/Logger.h>
16#include <zypp/media/MediaDIR.h>
17
18#include <sys/mount.h>
19#include <errno.h>
20
21 using std::endl;
22
23 namespace zypp {
24 namespace media {
25
27 //
28 // CLASS NAME : MediaDIR
29 //
31
33 //
34 //
35 // METHOD NAME : MediaDIR::MediaDIR
36 // METHOD TYPE : Constructor
37 //
38 // DESCRIPTION : Attach point is always _url.url().getPathName(),
39 // as files are not copied.
40 // Thus attach_point_hint_r is ignored.
41 //
42 MediaDIR::MediaDIR(const MirroredOrigin &origin,
43 const Pathname & /*attach_point_hint_r*/ )
44 : MediaHandler( origin, origin.authority().url().getPathName(),
45 "/", // urlpath below attachpoint
46 false ) // does_download
47 {
48 MIL << "MediaDIR::MediaDIR(" << url() << ")" << endl;
49 if( !origin.authority().url().getHost().empty())
50 {
51 ZYPP_THROW(MediaBadUrlException(origin.authority().url(),
52 "Hostname not allowed in the Url"
53 ));
54 }
55 }
56
58 //
59 //
60 // METHOD NAME : MediaDIR::attachTo
61 // METHOD TYPE : PMError
62 //
63 // DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
64 //
65 void MediaDIR::attachTo(bool next)
66 {
67 if(next)
68 ZYPP_THROW(MediaNotSupportedException(url()));
69
70 // fetch attach point from url again if needed ...
71 // it may happen that attachPointHint (and attachPoint())
72 // does not contain any path, because the directory has
73 // not existed while the handler was constructed.
74 if( attachPoint().empty() && !url().getPathName().empty())
75 {
76 Pathname real( getRealPath(url().getPathName()));
77
78 PathInfo adir( real);
79 if( adir.isDir())
80 {
81 // set attachpoint only if the dir exists
82 setAttachPoint( real, false);
83 }
84 else
85 {
86 ZYPP_THROW(MediaBadUrlException(url(),
87 "Specified path '" + url().getPathName() + "' is not a directory"
88 ));
89 }
90 }
91
92 // attach point is same as source path... we do not mount here
93 if(attachPoint().empty())
94 {
95 ZYPP_THROW(MediaBadUrlException(url(),
96 "The media URL does not provide any useable directory path"
97 ));
98 }
99 else
100 if(!PathInfo(attachPoint()).isDir())
101 {
102 ZYPP_THROW(MediaBadUrlException(url(),
103 "Specified path '" + attachPoint().asString() + "' is not a directory"
104 ));
105 }
106
107 MediaSourceRef media(new MediaSource("dir", attachPoint().asString()));
108 setMediaSource(media);
109 }
110
111
113 //
114 //
115 // METHOD NAME : MediaDIR::releaseFrom
116 // METHOD TYPE : void
117 //
118 // DESCRIPTION : Asserted that media is attached.
119 //
120 void MediaDIR::releaseFrom( const std::string & ejectDev )
121 {
122 return;
123 }
124
126 //
127 //
128 // METHOD NAME : MediaDIR::getFile
129 // METHOD TYPE : PMError
130 //
131 // DESCRIPTION : Asserted that media is attached.
132 //
133 void MediaDIR::getFile( const OnMediaLocation &file ) const
134 {
135 MediaHandler::getFile( file );
136 }
137
139 //
140 // METHOD NAME : MediaDIR::getDir
141 // METHOD TYPE : PMError
142 //
143 // DESCRIPTION : Asserted that media is attached.
144 //
145 void MediaDIR::getDir( const Pathname & dirname, bool recurse_r ) const
146 {
147 MediaHandler::getDir( dirname, recurse_r );
148 }
149
151 //
152 //
153 // METHOD NAME : MediaDIR::getDirInfo
154 // METHOD TYPE : PMError
155 //
156 // DESCRIPTION : Asserted that media is attached and retlist is empty.
157 //
158 void MediaDIR::getDirInfo( std::list<std::string> & retlist,
159 const Pathname & dirname, bool dots ) const
160 {
161 MediaHandler::getDirInfo( retlist, dirname, dots );
162 }
163
165 //
166 //
167 // METHOD NAME : MediaDIR::getDirInfo
168 // METHOD TYPE : PMError
169 //
170 // DESCRIPTION : Asserted that media is attached and retlist is empty.
171 //
172 void MediaDIR::getDirInfo( filesystem::DirContent & retlist,
173 const Pathname & dirname, bool dots ) const
174 {
175 MediaHandler::getDirInfo( retlist, dirname, dots );
176 }
177
178 bool MediaDIR::getDoesFileExist( const Pathname & filename ) const
179 {
180 return MediaHandler::getDoesFileExist( filename );
181 }
182
183 } // namespace media
184} // namespace zypp
MediaDIR.h
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::MirroredOrigin::authority
const OriginEndpoint & authority() const
Definition MirroredOrigin.cc:184
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition onmedialocation.h:37
zypp::OriginEndpoint::url
const zypp::Url & url() const
Definition MirroredOrigin.cc:51
zypp::Url::getHost
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition Url.cc:606
zypp::filesystem::PathInfo
Wrapper class for stat/lstat.
Definition PathInfo.h:226
zypp::filesystem::PathInfo::isDir
bool isDir() const
Definition PathInfo.h:296
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::media::MediaBadUrlException
Definition mediaexception.h:292
zypp::media::MediaDIR::getDirInfo
void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const override
Call concrete handler to provide a content list of directory on media via retlist.
Definition MediaDIR.cc:158
zypp::media::MediaDIR::getDoesFileExist
bool getDoesFileExist(const Pathname &filename) const override
check if a file exists
Definition MediaDIR.cc:178
zypp::media::MediaDIR::releaseFrom
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition MediaDIR.cc:120
zypp::media::MediaDIR::getFile
void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Definition MediaDIR.cc:133
zypp::media::MediaDIR::getDir
void getDir(const Pathname &dirname, bool recurse_r) const override
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition MediaDIR.cc:145
zypp::media::MediaDIR::MediaDIR
MediaDIR(const MirroredOrigin &origin, const Pathname &attach_point_hint_r)
Definition MediaDIR.cc:42
zypp::media::MediaDIR::attachTo
void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition MediaDIR.cc:65
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::MediaHandler
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
zypp::media::MediaHandler::url
Url url() const
Primary Url used.
Definition MediaHandler.h:502
zypp::media::MediaHandler::getDoesFileExist
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
Definition MediaHandler.cc:1326
zypp::media::MediaHandler::getRealPath
static std::string getRealPath(const std::string &path)
Definition MediaHandler.cc:122
zypp::media::MediaHandler::setMediaSource
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Definition MediaHandler.cc:432
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::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::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::MediaNotSupportedException
Definition mediaexception.h:352
zypp::media::MediaSource
Media source internally used by MediaManager and MediaHandler.
Definition MediaSource.h:38
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition PathInfo.h:526
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::media::MediaSourceRef
zypp::RW_pointer< MediaSource > MediaSourceRef
Definition MediaSource.h:125
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::asString
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
MIL
#define MIL
Definition Logger.h:100
Logger.h