libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include <fstream> 00014 00015 #include "zypp/repo/SrcPackageProvider.h" 00016 #include "zypp/PathInfo.h" 00017 #include "zypp/TmpPath.h" 00018 #include "zypp/SrcPackage.h" 00019 00020 using std::endl; 00021 00023 namespace zypp 00024 { 00025 00026 namespace repo 00027 { 00028 00030 namespace 00031 { 00032 00033 typedef std::string (SrcPackage::*inlined)() const; 00034 typedef OnMediaLocation (SrcPackage::*location)() const; 00035 00037 ManagedFile doProvideSrcPackage( repo::RepoMediaAccess & access_r, 00038 const SrcPackage & script_r, 00039 inlined inlined_r, location location_r ) 00040 { 00041 ManagedFile ret; 00042 00043 // 1st try inlined 00044 std::string inlined( (script_r.*inlined_r)() ); 00045 if ( ! inlined.empty() ) 00046 { 00047 // Take care the TmpFile goes out of scope BEFORE the 00048 // ofstream opens the file again. 00049 ret = ManagedFile( filesystem::TmpFile( filesystem::TmpPath::defaultLocation(), 00050 "zypp-script-"+script_r.name() ), 00051 filesystem::unlink ); 00052 std::ofstream str( ret.value().c_str() ); 00053 str << inlined << endl; 00054 } 00055 else 00056 { 00057 // otherwise try download 00058 OnMediaLocation location( (script_r.*location_r)() ); 00059 if ( ! location.filename().empty() ) 00060 { 00061 ret = access_r.provideFile( script_r.repoInfo(), location ); 00062 } 00063 else 00064 { 00065 // no script 00066 return ManagedFile(); 00067 } 00068 } 00069 00070 // HERE: got the script 00071 filesystem::chmod( ret, 0700 ); 00072 return ret; 00073 } 00074 00076 } // namespace 00078 00080 // 00081 // METHOD NAME : SrcPackageProvider::SrcPackageProvider 00082 // METHOD TYPE : Ctor 00083 // 00084 SrcPackageProvider::SrcPackageProvider( repo::RepoMediaAccess & access_r ) 00085 : _access( access_r ) 00086 {} 00087 00089 // 00090 // METHOD NAME : SrcPackageProvider::~SrcPackageProvider 00091 // METHOD TYPE : Dtor 00092 // 00093 SrcPackageProvider::~SrcPackageProvider() 00094 {} 00095 00096 ManagedFile SrcPackageProvider::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r ) const 00097 { 00098 return _access.provideFile( srcPackage_r->repoInfo(), srcPackage_r->location() ); 00099 } 00100 00102 } // namespace repo 00105 } // namespace zypp