libzypp: zypp/media/MediaDIR.cc Source File

libzypp 17.25.10

MediaDIR.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
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_r.getPathName(),
39 // as files are not copied.
40 // Thus attach_point_hint_r is ignored.
41 //
42 MediaDIR::MediaDIR( const Url & url_r,
43 const Pathname & /*attach_point_hint_r*/ )
44 : MediaHandler( url_r, url_r.getPathName(),
45 "/", // urlpath below attachpoint
46 false ) // does_download
47 {
48 MIL << "MediaDIR::MediaDIR(" << url_r << ")" << endl;
49 if( !url_r.getHost().empty())
50 {
51 ZYPP_THROW(MediaBadUrlException(url_r,
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 Pathname & filename , const ByteCount &expectedFileSize_r) const
134 {
135 MediaHandler::getFile( filename, expectedFileSize_r );
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
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
Logger.h
MIL
#define MIL
Definition: Logger.h:91
MediaDIR.h
zypp::ByteCount
Store and operate with byte count.
Definition: ByteCount.h:31
zypp::Url
Url manipulation class.
Definition: Url.h:92
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:583
zypp::filesystem::PathInfo
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:221
zypp::filesystem::PathInfo::isDir
bool isDir() const
Definition: PathInfo.h:290
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::media::MediaBadUrlException
Definition: MediaException.h:270
zypp::media::MediaDIR::getDirInfo
virtual 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::MediaDIR
MediaDIR(const Url &url_r, const Pathname &attach_point_hint_r)
Definition: MediaDIR.cc:42
zypp::media::MediaDIR::getDoesFileExist
virtual bool getDoesFileExist(const Pathname &filename) const override
check if a file exists
Definition: MediaDIR.cc:178
zypp::media::MediaDIR::releaseFrom
virtual void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition: MediaDIR.cc:120
zypp::media::MediaDIR::getDir
virtual 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::attachTo
virtual void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition: MediaDIR.cc:65
zypp::media::MediaDIR::getFile
virtual void getFile(const Pathname &filename, const ByteCount &expectedFileSize_r) const override
Call concrete handler to provide file below attach point.
Definition: MediaDIR.cc:133
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
zypp::media::MediaHandler::url
Url url() const
Url used.
Definition: MediaHandler.h:507
zypp::media::MediaHandler::getDoesFileExist
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
Definition: MediaHandler.cc:1375
zypp::media::MediaHandler::getRealPath
static std::string getRealPath(const std::string &path)
Definition: MediaHandler.cc:121
zypp::media::MediaHandler::getFile
virtual void getFile(const Pathname &filename, const ByteCount &expectedFileSize_r) const
Call concrete handler to provide file below attach point.
Definition: MediaHandler.cc:1234
zypp::media::MediaHandler::setMediaSource
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Definition: MediaHandler.cc:462
zypp::media::MediaHandler::setAttachPoint
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Definition: MediaHandler.cc:230
zypp::media::MediaHandler::attachPoint
Pathname attachPoint() const
Return the currently used attach point.
Definition: MediaHandler.cc:215
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:1268
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:1290
zypp::media::MediaNotSupportedException
Definition: MediaException.h:330
zypp::media::MediaSource
Media source internally used by MediaManager and MediaHandler.
Definition: MediaSource.h:37
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::asString
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
Definition: DefaultIntegral.h:98
zypp::RW_pointer< MediaSource >