00001
00002
00003
00004
00005
00006
00007
00008
00013 #include <iostream>
00014
00015 #include "zypp/base/Logger.h"
00016 #include "zypp/base/String.h"
00017 #include "zypp/media/MediaNFS.h"
00018 #include "zypp/media/Mount.h"
00019
00020 #include <dirent.h>
00021
00022 using namespace std;
00023
00024 namespace zypp {
00025 namespace media {
00026
00028
00029
00030
00032
00034
00035
00036
00037
00038
00039
00040
00041 MediaNFS::MediaNFS( const Url & url_r,
00042 const Pathname & attach_point_hint_r )
00043 : MediaHandler( url_r, attach_point_hint_r,
00044 "/",
00045 false )
00046 {
00047 MIL << "MediaNFS::MediaNFS(" << url_r << ", " << attach_point_hint_r << ")" << endl;
00048 }
00049
00051
00052
00053
00054
00055
00056
00057
00058 void MediaNFS::attachTo(bool next)
00059 {
00060 if(_url.getHost().empty())
00061 ZYPP_THROW(MediaBadUrlEmptyHostException(_url));
00062 if(next)
00063 ZYPP_THROW(MediaNotSupportedException(_url));
00064
00065 string path = _url.getHost();
00066 path += ':';
00067 path += Pathname(_url.getPathName()).asString();
00068
00069 MediaSourceRef media( new MediaSource("nfs", path));
00070 AttachedMedia ret( findAttachedMedia( media));
00071
00072 if( ret.mediaSource &&
00073 ret.attachPoint &&
00074 !ret.attachPoint->empty())
00075 {
00076 DBG << "Using a shared media "
00077 << ret.mediaSource->name
00078 << " attached on "
00079 << ret.attachPoint->path
00080 << endl;
00081
00082 removeAttachPoint();
00083 setAttachPoint(ret.attachPoint);
00084 setMediaSource(ret.mediaSource);
00085 return;
00086 }
00087
00088 const char* const filesystem = "nfs";
00089 std::string mountpoint = attachPoint().asString();
00090 Mount mount;
00091
00092 if( !isUseableAttachPoint(attachPoint()))
00093 {
00094 mountpoint = createAttachPoint().asString();
00095 if( mountpoint.empty())
00096 ZYPP_THROW( MediaBadAttachPointException(url()));
00097 setAttachPoint( mountpoint, true);
00098 }
00099
00100 string options = _url.getQueryParam("mountoptions");
00101 if(options.empty())
00102 {
00103 options="ro";
00104 }
00105
00106
00107
00108
00109 vector<string> optionList;
00110 str::split( options, std::back_inserter(optionList), "," );
00111 vector<string>::const_iterator it;
00112 for( it = optionList.begin(); it != optionList.end(); ++it ) {
00113 if ( *it == "lock" || *it == "nolock" ) break;
00114 }
00115 if ( it == optionList.end() ) {
00116 optionList.push_back( "nolock" );
00117 options = str::join( optionList, "," );
00118 }
00119
00120 mount.mount(path,mountpoint,filesystem,options);
00121
00122 setMediaSource(media);
00123
00124
00125
00126 int limit = 3;
00127 bool mountsucceeded;
00128 while( !(mountsucceeded=isAttached()) && --limit)
00129 {
00130 sleep(1);
00131 }
00132
00133 if( !mountsucceeded)
00134 {
00135 setMediaSource(MediaSourceRef());
00136 try
00137 {
00138 mount.umount(attachPoint().asString());
00139 }
00140 catch (const MediaException & excpt_r)
00141 {
00142 ZYPP_CAUGHT(excpt_r);
00143 }
00144 ZYPP_THROW(MediaMountException(
00145 "Unable to verify that the media was mounted",
00146 path, mountpoint
00147 ));
00148 }
00149 }
00150
00152
00153
00154
00155
00156
00157
00158 bool
00159 MediaNFS::isAttached() const
00160 {
00161 return checkAttached(true);
00162 }
00163
00165
00166
00167
00168
00169
00170
00171
00172 void MediaNFS::releaseFrom( bool eject )
00173 {
00174 Mount mount;
00175 mount.umount(attachPoint().asString());
00176 }
00177
00178
00180
00181
00182
00183
00184
00185
00186 void MediaNFS::getFile (const Pathname & filename) const
00187 {
00188 MediaHandler::getFile( filename );;
00189 }
00190
00192
00193
00194
00195
00196
00197
00198 void MediaNFS::getDir( const Pathname & dirname, bool recurse_r ) const
00199 {
00200 MediaHandler::getDir( dirname, recurse_r );
00201 }
00202
00204
00205
00206
00207
00208
00209
00210
00211 void MediaNFS::getDirInfo( std::list<std::string> & retlist,
00212 const Pathname & dirname, bool dots ) const
00213 {
00214 MediaHandler::getDirInfo( retlist, dirname, dots );
00215 }
00216
00218
00219
00220
00221
00222
00223
00224
00225 void MediaNFS::getDirInfo( filesystem::DirContent & retlist,
00226 const Pathname & dirname, bool dots ) const
00227 {
00228 MediaHandler::getDirInfo( retlist, dirname, dots );
00229 }
00230
00231 }
00232 }