00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef InstSrc_h
00025 #define InstSrc_h
00026
00027 #include <iosfwd>
00028 #include <list>
00029 #include <string>
00030
00031 #include <y2util/Pathname.h>
00032 #include <y2util/Url.h>
00033
00034 #include <y2pm/PMTypes.h>
00035
00036 #include <y2pm/PMPackagePtr.h>
00037 #include <y2pm/PMSelectionPtr.h>
00038 #include <y2pm/PMYouPatchPtr.h>
00039
00040 #include <y2pm/InstSrcPtr.h>
00041 #include <y2pm/InstSrcError.h>
00042
00043 #include <y2pm/MediaAccessPtr.h>
00044 #include <y2pm/InstSrcDescrPtr.h>
00045 #include <y2pm/InstSrcDataPtr.h>
00046
00048
00049
00053 class InstSrc: public CountedRep {
00054 REP_BODY(InstSrc);
00055
00056 private:
00057
00058 friend class InstSrcManager;
00059
00064 void _mgr_attach();
00065
00067 public:
00068
00072 typedef InstSrcError Error;
00073
00075 public:
00076
00080 typedef PM::NumericISrcID NumericISrcID;
00081 typedef PM::NumericISrcID UniqueID;
00082
00086 static const NumericISrcID noID;
00087
00091 NumericISrcID srcID() const { return _srcID; }
00092
00093 private:
00094
00098 static NumericISrcID _SRCID;
00099
00103 const NumericISrcID _srcID;
00104
00106 public:
00115 enum Type {
00116 T_UNKNOWN,
00117
00118 T_UnitedLinux,
00119 T_YUM,
00120
00121 T_PlainDir,
00122
00123 T_AUTODETECT
00124 };
00125
00130 static std::string toString( const Type t );
00131
00136 static Type fromString( std::string s );
00137
00141 friend std::ostream & operator<<( std::ostream & str, const Type obj );
00142
00143 private:
00144
00148 Pathname _cache;
00149
00153 bool _cache_deleteOnExit;
00154
00159 bool _may_use_cache;
00160
00164 static const Pathname _c_descr_dir;
00165
00169 static const Pathname _c_data_dir;
00170
00174 static const Pathname _c_media_dir;
00175
00179 Pathname cachePath( const Pathname & sub_r ) const { return( _cache + sub_r ); }
00180
00184 mutable Pathname previouslyDnlPackage;
00185
00186
00190 mutable int _specialCache;
00191
00192 public:
00193
00197 bool specialCache() const;
00198
00202 void rememberPreviouslyDnlPackage( const Pathname & newpath_r ) const;
00203
00207 Pathname cache_dir() const { return _cache; }
00208
00213 Pathname cache_descr_dir() const { return cachePath( _c_descr_dir ); }
00214
00219 Pathname cache_data_dir() const { return cachePath( _c_data_dir ); }
00220
00224 Pathname cache_media_dir() const { return cachePath( _c_media_dir ); }
00225
00226 private:
00227
00236 PMError _init_openCache( const Pathname & cachedir_r );
00237
00248 PMError _init_newCache( const Pathname & cachedir_r );
00249
00258 PMError _init_newMedia( const Url & mediaurl_r, const Pathname & produduct_dir_r,
00259 Type type_r );
00260
00264 PMError writeDescrCache();
00265
00266 protected:
00267
00274 InstSrc();
00275
00279 ~InstSrc();
00280
00281 private:
00282
00286 MediaAccessPtr _media;
00287
00291 InstSrcDescrPtr _descr;
00292
00296 InstSrcDataPtr _data;
00297
00298 public:
00299
00303 constInstSrcDescrPtr descr() const { return _descr; }
00304
00308 InstSrcDescrPtr descr() { return _descr; }
00309
00313 constInstSrcDataPtr data() const { return _data; }
00314
00318 InstSrcDataPtr data() { return _data; }
00319
00323 constMediaAccessPtr media() const { return _media; }
00324
00328 MediaAccessPtr media() { return _media; }
00329
00333 void preferredLocaleChanged() const;
00334
00335 private:
00336
00340 PMError enableSource( bool checkRefresh_r );
00341
00342 public:
00343
00349 PMError enableSource() { return enableSource( true ); }
00350
00355 PMError disableSource();
00356
00365 PMError refreshSource( bool force_r = false );
00366
00370 bool enabled() const { return _data; }
00371
00372 private:
00373
00378 mutable int _medianr;
00379
00383 PMError provideMedia (int medianr) const;
00384
00385 public:
00386
00396 PMError providePackage (int medianr, const Pathname& name, const Pathname& dir, Pathname& path_r) const;
00397
00407 PMError provideFile (int medianr, const Pathname& path, Pathname& file_r) const;
00408
00418 PMError provideDir (int medianr, const Pathname& path, Pathname& dir_r) const;
00419
00424 bool isRemote (void) const;
00425
00431 PMError changeUrl (const Url & newUrl_r);
00432
00433
00438 PMError releaseMedia( bool if_removable_r = false ) const;
00439
00440 public:
00441
00442 std::ostream & dumpOn( std::ostream & str ) const;
00443
00444 public:
00445
00454 static PMError vconstruct( InstSrcPtr & nsrc_r, const Pathname & cachedir_r );
00455
00466 static PMError vconstruct( InstSrcPtr & nsrc_r, const Pathname & cachedir_r,
00467 const Url & mediaurl_r, const Pathname & produduct_dir_r,
00468 Type type_r = T_AUTODETECT );
00469
00470 };
00471
00473
00474 #endif // InstSrc_h
00475