SrcPackageProvider.cc
Go to the documentation of this file.00001
00002
00003
00004
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
00044 std::string inlined( (script_r.*inlined_r)() );
00045 if ( ! inlined.empty() )
00046 {
00047
00048
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
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
00066 return ManagedFile();
00067 }
00068 }
00069
00070
00071 filesystem::chmod( ret, 0700 );
00072 return ret;
00073 }
00074
00076 }
00078
00080
00081
00082
00083
00084 SrcPackageProvider::SrcPackageProvider( repo::RepoMediaAccess & access_r )
00085 : _access( access_r )
00086 {}
00087
00089
00090
00091
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 }
00105 }