fixed replacing basearch (for fedora systems) - (bnc#637473)
[platform/upstream/libzypp.git] / zypp / repo / RepoVariables.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 #include <iostream>
11 #include <map>
12 #include <algorithm>
13 #include "zypp/base/String.h"
14 #include "zypp/repo/RepoException.h"
15 #include "zypp/ZConfig.h"
16 #include "zypp/ZYppFactory.h"
17 #include "RepoVariables.h"
18
19 using namespace std;
20
21 namespace zypp
22 {
23 namespace repo
24 {
25
26 RepoVariablesStringReplacer::RepoVariablesStringReplacer()
27 {}
28
29 RepoVariablesStringReplacer::~RepoVariablesStringReplacer()
30 {}
31
32 std::string RepoVariablesStringReplacer::operator()( const std::string &value ) const
33 {
34   string newvalue(value);
35
36   // $arch
37   Arch sysarch( ZConfig::instance().systemArchitecture() );
38   newvalue = str::gsub( newvalue, "$arch", sysarch.asString() );
39
40   // $basearch
41   Arch basearch( sysarch.baseArch( ) );
42
43   newvalue = str::gsub( newvalue, "$basearch", basearch.asString() );
44
45   // $releasever (Target::distributionVersion assumes root=/ if target not initialized)
46   newvalue = str::gsub( newvalue, "$releasever", Target::distributionVersion(Pathname()/*guess*/) );
47
48   return newvalue;
49 }
50
51 //////////////////////////////////////////////////////////////////////
52
53 RepoVariablesUrlReplacer::RepoVariablesUrlReplacer()
54 {}
55
56 RepoVariablesUrlReplacer::~RepoVariablesUrlReplacer()
57 {}
58
59 /*
60  * Replaces '$arch' and '$basearch' in the path and query part of the URL
61  * with the global ZYpp values. Examples:
62  *
63  * ftp://user:secret@site.net/$arch/ -> ftp://user:secret@site.net/i686/
64  * http://site.net/?basearch=$basearch -> http://site.net/?basearch=i386
65  */
66 Url RepoVariablesUrlReplacer::operator()( const Url &value ) const
67 {
68   Url newurl = value;
69   RepoVariablesStringReplacer replacer;
70   newurl.setPathData(replacer(value.getPathData()));
71   newurl.setQueryString(replacer(value.getQueryString()));
72
73   return newurl;
74 }
75
76 } // ns repo
77 } // ns zypp
78
79 // vim: set ts=2 sts=2 sw=2 et ai: