Imported Upstream version 15.0.0
[platform/upstream/libzypp.git] / zypp / repo / Downloader.cc
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 }
32 Downloader::~Downloader()
33 {
34 }
35
36 RepoStatus Downloader::status( MediaSetAccess &media )
37 {
38   WAR << "Non implemented" << endl;
39   return RepoStatus();
40 }
41
42 void Downloader::download( MediaSetAccess &media,
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   SignatureFileChecker sigchecker;
55
56   enqueue( OnMediaLocation( sigpath, 1 ).setOptional( true ) );
57   start( destdir_r, media_r );
58   reset();
59
60   // only add the signature if it exists
61   if ( PathInfo(destdir_r / sigpath).isExist() )
62     sigchecker = SignatureFileChecker( destdir_r / sigpath );
63
64   enqueue( OnMediaLocation( keypath, 1 ).setOptional( true ) );
65   start( destdir_r, media_r );
66   reset();
67
68   KeyContext context;
69   context.setRepoInfo( repoInfo() );
70   // only add the key if it exists
71   if ( PathInfo(destdir_r / keypath).isExist() )
72     sigchecker.addPublicKey( destdir_r / keypath, context );
73   else
74     // set the checker context even if the key is not known (unsigned repo, key
75     // file missing; bnc #495977)
76     sigchecker.setKeyContext( context );
77
78   if ( ! repoInfo().gpgCheck() )
79   {
80     WAR << "Signature checking disabled in config of repository " << repoInfo().alias() << endl;
81   }
82   enqueue( OnMediaLocation( masterIndex_r, 1 ),
83            repoInfo().gpgCheck() ? FileChecker(sigchecker) : FileChecker(NullFileChecker()) );
84   start( destdir_r, media_r );
85   reset();
86 }
87
88
89 }// ns repo
90 } // ns zypp
91
92
93