MediaDIR.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00013 #include <iostream>
00014 
00015 #include "zypp/base/Logger.h"
00016 #include "zypp/media/MediaDIR.h"
00017 
00018 #include <sys/mount.h>
00019 #include <errno.h>
00020 
00021 using namespace std;
00022 
00023 namespace zypp {
00024   namespace media {
00025 
00027     //
00028     //  CLASS NAME : MediaDIR
00029     //
00031 
00033     //
00034     //
00035     //  METHOD NAME : MediaDIR::MediaDIR
00036     //  METHOD TYPE : Constructor
00037     //
00038     //  DESCRIPTION : Attach point is always url_r.getPathName(),
00039     //                as files are not copied.
00040     //                Thus attach_point_hint_r is ignored.
00041     //
00042     MediaDIR::MediaDIR( const Url &      url_r,
00043                         const Pathname & /*attach_point_hint_r*/ )
00044         : MediaHandler( url_r, url_r.getPathName(),
00045                     "/",    // urlpath below attachpoint
00046                     false ) // does_download
00047     {
00048         MIL << "MediaDIR::MediaDIR(" << url_r << ")" << endl;
00049         if( !url_r.getHost().empty())
00050         {
00051           ZYPP_THROW(MediaBadUrlException(url_r,
00052             "Hostname not allowed in the Url"
00053           ));
00054         }
00055     }
00056 
00058     //
00059     //
00060     //  METHOD NAME : MediaDIR::attachTo
00061     //  METHOD TYPE : PMError
00062     //
00063     //  DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
00064     //
00065     void MediaDIR::attachTo(bool next)
00066     {
00067       if(next)
00068         ZYPP_THROW(MediaNotSupportedException(url()));
00069 
00070       // fetch attach point from url again if needed ...
00071       // it may happen that attachPointHint (and attachPoint())
00072       // does not contain any path, because the directory has
00073       // not existed while the handler was constructed.
00074       if( attachPoint().empty() && !url().getPathName().empty())
00075       {
00076         Pathname real( getRealPath(url().getPathName()));
00077 
00078         PathInfo adir( real);
00079         if( adir.isDir())
00080         {
00081           // set attachpoint only if the dir exists
00082           setAttachPoint( real, false);
00083         }
00084         else
00085         {
00086           ZYPP_THROW(MediaBadUrlException(url(),
00087             "Specified path '" + url().getPathName() + "' is not a directory"
00088           ));
00089         }
00090       }
00091 
00092       // attach point is same as source path... we do not mount here
00093       if(attachPoint().empty())
00094       {
00095         ZYPP_THROW(MediaBadUrlException(url(),
00096           "The media URL does not provide any useable directory path"
00097         ));
00098       }
00099       else
00100       if(!PathInfo(attachPoint()).isDir())
00101       {
00102         ZYPP_THROW(MediaBadUrlException(url(),
00103           "Specified path '" + attachPoint().asString() + "' is not a directory"
00104         ));
00105       }
00106 
00107       MediaSourceRef media(new MediaSource("dir", attachPoint().asString()));
00108       setMediaSource(media);
00109     }
00110 
00111 
00113     //
00114     //
00115     //  METHOD NAME : MediaDIR::releaseFrom
00116     //  METHOD TYPE : void
00117     //
00118     //  DESCRIPTION : Asserted that media is attached.
00119     //
00120     void MediaDIR::releaseFrom( const std::string & ejectDev )
00121     {
00122       return;
00123     }
00124 
00126     //
00127     //
00128     //  METHOD NAME : MediaDIR::getFile
00129     //  METHOD TYPE : PMError
00130     //
00131     //  DESCRIPTION : Asserted that media is attached.
00132     //
00133     void MediaDIR::getFile( const Pathname & filename ) const
00134     {
00135       MediaHandler::getFile( filename );
00136     }
00137 
00139     //
00140     //  METHOD NAME : MediaDIR::getDir
00141     //  METHOD TYPE : PMError
00142     //
00143     //  DESCRIPTION : Asserted that media is attached.
00144     //
00145     void MediaDIR::getDir( const Pathname & dirname, bool recurse_r ) const
00146     {
00147       MediaHandler::getDir( dirname, recurse_r );
00148     }
00149 
00151     //
00152     //
00153     //  METHOD NAME : MediaDIR::getDirInfo
00154     //  METHOD TYPE : PMError
00155     //
00156     //  DESCRIPTION : Asserted that media is attached and retlist is empty.
00157     //
00158     void MediaDIR::getDirInfo( std::list<std::string> & retlist,
00159                                const Pathname & dirname, bool dots ) const
00160     {
00161       MediaHandler::getDirInfo( retlist, dirname, dots );
00162     }
00163 
00165     //
00166     //
00167     //  METHOD NAME : MediaDIR::getDirInfo
00168     //  METHOD TYPE : PMError
00169     //
00170     //  DESCRIPTION : Asserted that media is attached and retlist is empty.
00171     //
00172     void MediaDIR::getDirInfo( filesystem::DirContent & retlist,
00173                                const Pathname & dirname, bool dots ) const
00174     {
00175       MediaHandler::getDirInfo( retlist, dirname, dots );
00176     }
00177 
00178     bool MediaDIR::getDoesFileExist( const Pathname & filename ) const
00179     {
00180       return MediaHandler::getDoesFileExist( filename );
00181     }
00182 
00183   } // namespace media
00184 } // namespace zypp

doxygen