libzypp  13.10.6
SrcPackageProvider.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <fstream>
14 
16 #include "zypp/PathInfo.h"
17 #include "zypp/TmpPath.h"
18 #include "zypp/SrcPackage.h"
19 
20 using std::endl;
21 
23 namespace zypp
24 {
25  namespace repo
27  {
28 
30  namespace
31  {
32 
33  typedef std::string (SrcPackage::*inlined)() const;
34  typedef OnMediaLocation (SrcPackage::*location)() const;
35 
37  ManagedFile doProvideSrcPackage( repo::RepoMediaAccess & access_r,
38  const SrcPackage & script_r,
39  inlined inlined_r, location location_r )
40  {
41  ManagedFile ret;
42 
43  // 1st try inlined
44  std::string inlined( (script_r.*inlined_r)() );
45  if ( ! inlined.empty() )
46  {
47  // Take care the TmpFile goes out of scope BEFORE the
48  // ofstream opens the file again.
49  ret = ManagedFile( filesystem::TmpFile( filesystem::TmpPath::defaultLocation(),
50  "zypp-script-"+script_r.name() ),
52  std::ofstream str( ret.value().c_str() );
53  str << inlined << endl;
54  }
55  else
56  {
57  // otherwise try download
58  OnMediaLocation location( (script_r.*location_r)() );
59  if ( ! location.filename().empty() )
60  {
61  ret = access_r.provideFile( script_r.repoInfo(), location );
62  }
63  else
64  {
65  // no script
66  return ManagedFile();
67  }
68  }
69 
70  // HERE: got the script
71  filesystem::chmod( ret, 0700 );
72  return ret;
73  }
74 
76  } // namespace
78 
80  //
81  // METHOD NAME : SrcPackageProvider::SrcPackageProvider
82  // METHOD TYPE : Ctor
83  //
85  : _access( access_r )
86  {}
87 
89  //
90  // METHOD NAME : SrcPackageProvider::~SrcPackageProvider
91  // METHOD TYPE : Dtor
92  //
94  {}
95 
96  ManagedFile SrcPackageProvider::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r ) const
97  {
98  return _access.provideFile( srcPackage_r->repoInfo(), srcPackage_r->location() );
99  }
100 
102  } // namespace repo
105 } // namespace zypp
ManagedFile provideFile(RepoInfo repo_r, const OnMediaLocation &loc_r, const ProvideFilePolicy &policy_r)
Provide a file from a Repository.
int chmod(const Pathname &path, mode_t mode)
Like &#39;chmod&#39;.
Definition: PathInfo.cc:1021
static const Pathname & defaultLocation()
Definition: TmpPath.cc:157
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition: ManagedFile.h:27
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r) const
Provide SrcPackage in a local file.
SrcPackageProvider(repo::RepoMediaAccess &access_r)
Ctor.
int unlink(const Pathname &path)
Like &#39;unlink&#39;.
Definition: PathInfo.cc:660
Provides files from different repos.
Reference counted access to a _Tp object calling a custom Dispose function when the last AutoDispose ...
Definition: AutoDispose.h:92