1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaDIR.cc
15 #include "zypp/base/Logger.h"
16 #include "zypp/media/MediaDIR.h"
18 #include <sys/mount.h>
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : MediaDIR
30 ///////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
35 // METHOD NAME : MediaDIR::MediaDIR
36 // METHOD TYPE : Constructor
38 // DESCRIPTION : Attach point is always url_r.getPathName(),
39 // as files are not copied.
40 // Thus attach_point_hint_r is ignored.
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
48 MIL << "MediaDIR::MediaDIR(" << url_r << ")" << endl;
49 if( !url_r.getHost().empty())
51 ZYPP_THROW(MediaBadUrlException(url_r,
52 "Hostname not allowed in the Url"
57 ///////////////////////////////////////////////////////////////////
60 // METHOD NAME : MediaDIR::attachTo
61 // METHOD TYPE : PMError
63 // DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
65 void MediaDIR::attachTo(bool next)
68 ZYPP_THROW(MediaNotSupportedException(url()));
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())
76 Pathname real( getRealPath(url().getPathName()));
81 // set attachpoint only if the dir exists
82 setAttachPoint( real, false);
86 ZYPP_THROW(MediaBadUrlException(url(),
87 "Specified path '" + url().getPathName() + "' is not a directory"
92 // attach point is same as source path... we do not mount here
93 if(attachPoint().empty())
95 ZYPP_THROW(MediaBadUrlException(url(),
96 "The media URL does not provide any useable directory path"
100 if(!PathInfo(attachPoint()).isDir())
102 ZYPP_THROW(MediaBadUrlException(url(),
103 "Specified path '" + attachPoint().asString() + "' is not a directory"
107 MediaSourceRef media(new MediaSource("dir", attachPoint().asString()));
108 setMediaSource(media);
112 ///////////////////////////////////////////////////////////////////
115 // METHOD NAME : MediaDIR::releaseFrom
116 // METHOD TYPE : void
118 // DESCRIPTION : Asserted that media is attached.
120 void MediaDIR::releaseFrom( const std::string & ejectDev )
125 ///////////////////////////////////////////////////////////////////
128 // METHOD NAME : MediaDIR::getFile
129 // METHOD TYPE : PMError
131 // DESCRIPTION : Asserted that media is attached.
133 void MediaDIR::getFile(const Pathname & filename , const ByteCount &expectedFileSize_r) const
135 MediaHandler::getFile( filename, expectedFileSize_r );
138 ///////////////////////////////////////////////////////////////////
140 // METHOD NAME : MediaDIR::getDir
141 // METHOD TYPE : PMError
143 // DESCRIPTION : Asserted that media is attached.
145 void MediaDIR::getDir( const Pathname & dirname, bool recurse_r ) const
147 MediaHandler::getDir( dirname, recurse_r );
150 ///////////////////////////////////////////////////////////////////
153 // METHOD NAME : MediaDIR::getDirInfo
154 // METHOD TYPE : PMError
156 // DESCRIPTION : Asserted that media is attached and retlist is empty.
158 void MediaDIR::getDirInfo( std::list<std::string> & retlist,
159 const Pathname & dirname, bool dots ) const
161 MediaHandler::getDirInfo( retlist, dirname, dots );
164 ///////////////////////////////////////////////////////////////////
167 // METHOD NAME : MediaDIR::getDirInfo
168 // METHOD TYPE : PMError
170 // DESCRIPTION : Asserted that media is attached and retlist is empty.
172 void MediaDIR::getDirInfo( filesystem::DirContent & retlist,
173 const Pathname & dirname, bool dots ) const
175 MediaHandler::getDirInfo( retlist, dirname, dots );
178 bool MediaDIR::getDoesFileExist( const Pathname & filename ) const
180 return MediaHandler::getDoesFileExist( filename );