1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaNFS.cc
15 #include "zypp/base/Logger.h"
16 #include "zypp/base/String.h"
17 #include "zypp/media/MediaNFS.h"
18 #include "zypp/media/Mount.h"
27 ///////////////////////////////////////////////////////////////////
29 // CLASS NAME : MediaNFS
31 ///////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
36 // METHOD NAME : MediaNFS::MediaNFS
37 // METHOD TYPE : Constructor
41 MediaNFS::MediaNFS( const Url & url_r,
42 const Pathname & attach_point_hint_r )
43 : MediaHandler( url_r, attach_point_hint_r,
44 "/", // urlpath at attachpoint
45 false ) // does_download
47 MIL << "MediaNFS::MediaNFS(" << url_r << ", " << attach_point_hint_r << ")" << endl;
50 ///////////////////////////////////////////////////////////////////
53 // METHOD NAME : MediaNFS::attachTo
54 // METHOD TYPE : PMError
56 // DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
58 void MediaNFS::attachTo(bool next)
60 if(_url.getHost().empty())
61 ZYPP_THROW(MediaBadUrlEmptyHostException(_url));
63 ZYPP_THROW(MediaNotSupportedException(_url));
65 string path = _url.getHost();
67 path += Pathname(_url.getPathName()).asString();
69 MediaSourceRef media( new MediaSource("nfs", path));
70 AttachedMedia ret( findAttachedMedia( media));
72 if( ret.mediaSource &&
74 !ret.attachPoint->empty())
76 DBG << "Using a shared media "
77 << ret.mediaSource->name
79 << ret.attachPoint->path
83 setAttachPoint(ret.attachPoint);
84 setMediaSource(ret.mediaSource);
88 const char* const filesystem = "nfs";
89 std::string mountpoint = attachPoint().asString();
92 if( !isUseableAttachPoint(attachPoint()))
94 mountpoint = createAttachPoint().asString();
95 if( mountpoint.empty())
96 ZYPP_THROW( MediaBadAttachPointException(url()));
97 setAttachPoint( mountpoint, true);
100 string options = _url.getQueryParam("mountoptions");
106 // Add option "nolock", unless option "lock" or "unlock" is already set.
107 // This should prevent the mount command hanging when the portmapper isn't
109 vector<string> optionList;
110 str::split( options, std::back_inserter(optionList), "," );
111 vector<string>::const_iterator it;
112 for( it = optionList.begin(); it != optionList.end(); ++it ) {
113 if ( *it == "lock" || *it == "nolock" ) break;
115 if ( it == optionList.end() ) {
116 optionList.push_back( "nolock" );
117 options = str::join( optionList, "," );
120 mount.mount(path,mountpoint,filesystem,options);
122 setMediaSource(media);
124 // wait for /etc/mtab update ...
125 // (shouldn't be needed)
128 while( !(mountsucceeded=isAttached()) && --limit)
135 setMediaSource(MediaSourceRef());
138 mount.umount(attachPoint().asString());
140 catch (const MediaException & excpt_r)
142 ZYPP_CAUGHT(excpt_r);
144 ZYPP_THROW(MediaMountException(
145 "Unable to verify that the media was mounted",
151 ///////////////////////////////////////////////////////////////////
153 // METHOD NAME : MediaNFS::isAttached
154 // METHOD TYPE : bool
156 // DESCRIPTION : Override check if media is attached.
159 MediaNFS::isAttached() const
161 return checkAttached(false, true);
164 ///////////////////////////////////////////////////////////////////
167 // METHOD NAME : MediaNFS::releaseFrom
168 // METHOD TYPE : PMError
170 // DESCRIPTION : Asserted that media is attached.
172 void MediaNFS::releaseFrom( bool eject )
175 mount.umount(attachPoint().asString());
179 ///////////////////////////////////////////////////////////////////
181 // METHOD NAME : MediaNFS::getFile
182 // METHOD TYPE : PMError
184 // DESCRIPTION : Asserted that media is attached.
186 void MediaNFS::getFile (const Pathname & filename) const
188 MediaHandler::getFile( filename );;
191 ///////////////////////////////////////////////////////////////////
193 // METHOD NAME : MediaNFS::getDir
194 // METHOD TYPE : PMError
196 // DESCRIPTION : Asserted that media is attached.
198 void MediaNFS::getDir( const Pathname & dirname, bool recurse_r ) const
200 MediaHandler::getDir( dirname, recurse_r );
203 ///////////////////////////////////////////////////////////////////
206 // METHOD NAME : MediaNFS::getDirInfo
207 // METHOD TYPE : PMError
209 // DESCRIPTION : Asserted that media is attached and retlist is empty.
211 void MediaNFS::getDirInfo( std::list<std::string> & retlist,
212 const Pathname & dirname, bool dots ) const
214 MediaHandler::getDirInfo( retlist, dirname, dots );
217 ///////////////////////////////////////////////////////////////////
220 // METHOD NAME : MediaNFS::getDirInfo
221 // METHOD TYPE : PMError
223 // DESCRIPTION : Asserted that media is attached and retlist is empty.
225 void MediaNFS::getDirInfo( filesystem::DirContent & retlist,
226 const Pathname & dirname, bool dots ) const
228 MediaHandler::getDirInfo( retlist, dirname, dots );