libzypp  16.22.5
Downloader.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #include <fstream>
11 #include "zypp/base/String.h"
12 #include "zypp/base/Logger.h"
13 #include "zypp/base/Gettext.h"
14 
15 #include "Downloader.h"
16 #include "zypp/KeyContext.h"
17 #include "zypp/ZYppCallbacks.h"
18 
19 using namespace std;
20 
21 namespace zypp
22 {
23 namespace repo
24 {
25 
26 Downloader::Downloader()
27 {
28 }
29 Downloader::Downloader(const RepoInfo & repoinfo) : _repoinfo(repoinfo)
30 {
31 }
33 {
34 }
35 
37 {
38  WAR << "Non implemented" << endl;
39  return RepoStatus();
40 }
41 
43  const Pathname &dest_dir,
44  const ProgressData::ReceiverFnc & progress )
45 {
46  WAR << "Non implemented" << endl;
47 }
48 
49 void Downloader::defaultDownloadMasterIndex( MediaSetAccess & media_r, const Pathname & destdir_r, const Pathname & masterIndex_r )
50 {
51  Pathname sigpath = masterIndex_r.extend( ".asc" );
52  Pathname keypath = masterIndex_r.extend( ".key" );
53 
54  // always download them, even if repoGpgCheck is disabled
55  enqueue( OnMediaLocation( sigpath, 1 ).setOptional( true ).setDownloadSize( ByteCount( 20, ByteCount::MB ) ) );
56  enqueue( OnMediaLocation( keypath, 1 ).setOptional( true ).setDownloadSize( ByteCount( 20, ByteCount::MB ) ) );
57  start( destdir_r, media_r );
58  reset();
59 
60  FileChecker checker; // set to sigchecker if appropriate, else Null.
61  SignatureFileChecker sigchecker;
62  bool isSigned = PathInfo(destdir_r / sigpath).isExist();
63 
64  if ( repoInfo().repoGpgCheck() )
65  {
66  if ( isSigned || repoInfo().repoGpgCheckIsMandatory() )
67  {
68  // only add the signature if it exists
69  if ( isSigned )
70  sigchecker = SignatureFileChecker( destdir_r / sigpath );
71 
72  KeyContext context;
73  context.setRepoInfo( repoInfo() );
74  // only add the key if it exists
75  if ( PathInfo(destdir_r / keypath).isExist() )
76  sigchecker.addPublicKey( destdir_r / keypath, context );
77  else
78  // set the checker context even if the key is not known (unsigned repo, key
79  // file missing; bnc #495977)
80  sigchecker.setKeyContext( context );
81 
82  checker = FileChecker( ref(sigchecker) ); // ref() to the local sigchecker is important as we want back fileValidated!
83  }
84  else
85  {
86  WAR << "Accept unsigned repository because repoGpgCheck is not mandatory for " << repoInfo().alias() << endl;
87  }
88  }
89  else
90  {
91  WAR << "Signature checking disabled in config of repository " << repoInfo().alias() << endl;
92  }
93 
94  enqueue( OnMediaLocation( masterIndex_r, 1 ).setDownloadSize( ByteCount( 20, ByteCount::MB ) ), checker ? checker : FileChecker(NullFileChecker()) );
95  start( destdir_r, media_r );
96  reset();
97 
98  // Accepted!
99  _repoinfo.setMetadataPath( destdir_r );
100  if ( isSigned )
102  else
103  _repoinfo.setValidRepoSignature( indeterminate );
104 }
105 
106 
107 }// ns repo
108 } // ns zypp
109 
110 
111 
Interface to gettext.
Checks for nothing Used as the default checker.
Definition: FileChecker.h:172
std::string alias() const
unique identifier for this source.
void defaultDownloadMasterIndex(MediaSetAccess &media_r, const Pathname &destdir_r, const Pathname &masterIndex_r)
Common workflow downloading a (signed) master index file.
Definition: Downloader.cc:49
Describes a path on a certain media amongs as the information required to download it...
Checks for the validity of a signature.
Definition: FileChecker.h:93
Store and operate with byte count.
Definition: ByteCount.h:30
What is known about a repository.
Definition: RepoInfo.h:71
static const Unit MB
1000^2 Byte
Definition: ByteCount.h:60
const RepoInfo & repoInfo() const
Definition: Downloader.h:58
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:139
void addPublicKey(const PublicKey &publickey, const KeyContext &keycontext=KeyContext())
add a public key to the list of known keys
Definition: FileChecker.cc:125
void setValidRepoSignature(TriBool value_r)
Set the value for validRepoSignature (or indeterminate if unsigned).
Definition: RepoInfo.cc:418
void reset()
Reset the transfer (jobs) list.
Definition: Fetcher.cc:867
#define WAR
Definition: Logger.h:65
void setMetadataPath(const Pathname &path)
Set the path where the local metadata is stored.
Definition: RepoInfo.cc:521
void start(const Pathname &dest_dir, MediaSetAccess &media, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
start the transfer to a destination directory dest_dir You have to provde a media set access media to...
Definition: Fetcher.cc:872
virtual void download(MediaSetAccess &media, const Pathname &dest_dir, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Download metadata to a local directory.
Definition: Downloader.cc:42
bool fileValidated() const
Return whether the last file passed to operator() was actually sucessfully verified.
Definition: FileChecker.h:137
Track changing files or directories.
Definition: RepoStatus.h:38
function< void(const Pathname &file)> FileChecker
Functor signature used to check files.
Definition: FileChecker.h:28
virtual RepoStatus status(MediaSetAccess &media)
Status of the remote repository.
Definition: Downloader.cc:36
void setRepoInfo(const RepoInfo &repoinfo)
Definition: KeyContext.h:16
void enqueue(const OnMediaLocation &resource, const FileChecker &checker=FileChecker())
Enqueue a object for transferal, they will not be transferred until start() is called.
Definition: Fetcher.cc:857
Media access layer responsible for handling files distributed on a set of media with media change and...
void setKeyContext(const KeyContext &keycontext)
Set context for this checker.
Definition: FileChecker.cc:119