00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_MEDIA_MEDIAACCESS_H
00013 #define ZYPP_MEDIA_MEDIAACCESS_H
00014
00015 #include <iosfwd>
00016 #include <map>
00017 #include <list>
00018 #include <string>
00019
00020 #include "zypp/base/ReferenceCounted.h"
00021 #include "zypp/base/NonCopyable.h"
00022 #include "zypp/base/PtrTypes.h"
00023
00024 #include "zypp/Pathname.h"
00025 #include "zypp/PathInfo.h"
00026
00027 #include "zypp/media/MediaException.h"
00028 #include "zypp/media/MediaSource.h"
00029
00030 #include "zypp/Url.h"
00031
00032 namespace zypp {
00033 namespace media {
00034
00035 class MediaHandler;
00036
00038
00039
00049 class MediaAccess : public base::ReferenceCounted, private base::NonCopyable
00050 {
00051 public:
00052 typedef intrusive_ptr<MediaAccess> Ptr;
00053 typedef intrusive_ptr<const MediaAccess> constPtr;
00054
00055 private:
00056
00057 static const Pathname _noPath;
00058
00063 MediaHandler * _handler;
00064
00065 friend class MediaManager;
00066 friend class MediaManager_Impl;
00067
00068 AttachedMedia attachedMedia() const;
00069
00070 bool isSharedMedia() const;
00071
00072 void resetParentId();
00073 bool dependsOnParent() const;
00074 bool dependsOnParent(MediaAccessId parentId,
00075 bool exactIdMatch) const;
00076
00077 public:
00078
00082 MediaAccess();
00083
00094 void open( const Url& url, const Pathname & preferred_attach_point = "" );
00095
00099 bool isOpen() const { return( _handler != 0 ); }
00100
00105 bool downloads() const;
00106
00117 static
00118 bool downloads(const Url &url);
00128 static
00129 bool canBeVolatile(const Url &url);
00130
00134 std::string protocol() const;
00135
00139 Url url() const;
00140
00147 void close();
00148
00149 public:
00150
00161 void attach(bool next = false);
00162
00169 bool isAttached() const;
00170
00179 Pathname localRoot() const;
00180
00187 Pathname localPath( const Pathname & pathname ) const;
00188
00202 void disconnect();
00203
00211 void release( bool eject = false );
00212
00230 void provideFile( const Pathname & filename, bool cached = false, bool checkonly = false ) const;
00231
00239 void releaseFile( const Pathname & filename ) const;
00240
00250 void provideDir( const Pathname & dirname ) const;
00251
00261 void provideDirTree( const Pathname & dirname ) const;
00262
00270 void releaseDir( const Pathname & dirname ) const;
00271
00283 void releasePath( const Pathname & pathname ) const;
00284
00285 public:
00286
00300 void dirInfo( std::list<std::string> & retlist,
00301 const Pathname & dirname, bool dots = true ) const;
00302
00315 void dirInfo( filesystem::DirContent & retlist,
00316 const Pathname & dirname, bool dots = true ) const;
00317
00326 bool doesFileExist( const Pathname & filename ) const;
00327
00331 virtual ~MediaAccess();
00332
00333 public:
00334
00335 virtual std::ostream & dumpOn( std::ostream & str ) const;
00336
00337 public:
00348 void getFile( const Url &from, const Pathname &to );
00349
00350 public:
00351
00372 class FileProvider {
00373 FileProvider( const FileProvider & );
00374 FileProvider & operator=( const FileProvider & );
00375 private:
00376 MediaAccess::constPtr _media;
00377 Pathname _file;
00378 Pathname _local_file;
00379 public:
00383 FileProvider( MediaAccess::constPtr media_r, const Pathname & file_r )
00384 : _media( media_r )
00385 , _file( file_r )
00386 , _local_file( "" )
00387 {
00388 if ( _file.empty() ) {
00389 ZYPP_THROW(MediaBadFilenameException(_file.asString()));
00390 } else if ( _media ) {
00391 try {
00392 _media->provideFile( _file );
00393 _local_file = _media->localPath( _file );
00394 }
00395 catch (const MediaException & excpt_r)
00396 {
00397 ZYPP_CAUGHT(excpt_r);
00398 _media = NULL;
00399 ZYPP_RETHROW(excpt_r);
00400 }
00401 }
00402 }
00403
00404 ~FileProvider() {
00405 if ( _media )
00406 {
00407 try {
00408 _media->releaseFile( _file );
00409 }
00410 catch (const MediaException &excpt_r)
00411 {
00412 ZYPP_CAUGHT(excpt_r);
00413 }
00414 catch(...) {}
00415 }
00416 }
00417
00418 public:
00419
00424 Pathname localFile() const { return _local_file; }
00425
00430 Pathname operator()() const {
00431 if ( _media )
00432 return _media->localPath( _file );
00433 return Pathname();
00434 }
00435 };
00436 };
00437
00438 std::ostream & operator<<( std::ostream & str, const MediaAccess & obj );
00439
00441
00442 }
00443 }
00444
00445 #endif // ZYPP_MEDIA_MEDIAACCESS_H
00446