Browse code

tdnf add retry option

Change-Id: Id88d8f9336c1e4b8afc640c9a07bf3e0e0074d14
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5676
Reviewed-by: Anish Swaminathan <anishs@vmware.com>
Tested-by: Anish Swaminathan <anishs@vmware.com>

Priyesh Padmavilasom authored on 2018/09/13 08:36:24
Showing 2 changed files
... ...
@@ -4,7 +4,7 @@
4 4
 Summary:        dnf/yum equivalent using C libs
5 5
 Name:           tdnf
6 6
 Version:        1.2.3
7
-Release:        2%{?dist}
7
+Release:        3%{?dist}
8 8
 Vendor:         VMware, Inc.
9 9
 Distribution:   Photon
10 10
 License:        LGPLv2.1,GPLv2
... ...
@@ -27,6 +27,7 @@ Source1:        cache-updateinfo
27 27
 Source2:        cache-updateinfo.service
28 28
 Source3:        cache-updateinfo.timer
29 29
 Source4:        updateinfo.sh
30
+Patch0:         tdnf_add_retry_to_downloads.patch
30 31
 
31 32
 %description
32 33
 tdnf is a yum/dnf equivalent
... ...
@@ -50,6 +51,7 @@ Library providing cli libs for tdnf like clients.
50 50
 
51 51
 %prep
52 52
 %setup -q
53
+%patch0 -p1
53 54
 
54 55
 %build
55 56
 sed -i 's/tdnf, 1.2.0/tdnf, 1.2.3/' configure.ac
... ...
@@ -151,6 +153,8 @@ systemctl try-restart tdnf-cache-updateinfo.timer >/dev/null 2>&1 || :
151 151
     %{_libdir}/libtdnfcli.so.*
152 152
 
153 153
 %changelog
154
+*   Wed Sep 12 2018 Priyesh Padmavilasom <ppadmavilasom@vmware.com> 1.2.3-3
155
+-   retry option for downloads. default retry on download failures to 10
154 156
 *   Fri Apr 27 2018 Xiaolin Li <xiaolinl@vmware.com> 1.2.3-2
155 157
 -   Requires hawkey >= 2017.1-6
156 158
 *   Thu Apr 05 2018 Xiaolin Li <xiaolinl@vmware.com> 1.2.3-1
157 159
new file mode 100644
... ...
@@ -0,0 +1,196 @@
0
+From cd08feba10c857f3e1a097968578b7df1a0a3aff Mon Sep 17 00:00:00 2001
1
+From: Priyesh Padmavilasom <ppadmavilasom@vmware.com>
2
+Date: Mon, 10 Sep 2018 15:33:23 +0000
3
+Subject: [PATCH] add retry for downloads
4
+
5
+Change-Id: I911bad2dbf90c30fe158e756a38316bcc6ae1db6
6
+---
7
+
8
+diff --git a/client/prototypes.h b/client/prototypes.h
9
+index c6d09ed..489bc3e 100644
10
+--- a/client/prototypes.h
11
+@@ -791,6 +791,12 @@
12
+ 
13
+ //utils.c
14
+ uint32_t
15
++TDNFGetOptValue(
16
++    PTDNF pTdnf,
17
++    const char *pszKey,
18
++    char **ppszValue
19
++    );
20
++uint32_t
21
+ TDNFIsSystemError(
22
+     uint32_t dwError
23
+     );
24
+diff --git a/client/remoterepo.c b/client/remoterepo.c
25
+index d5bccf0..94d5e33 100644
26
+--- a/client/remoterepo.c
27
+@@ -85,8 +85,9 @@
28
+     goto cleanup;
29
+ }
30
+ 
31
++static
32
+ uint32_t
33
+-TDNFDownloadFile(
34
++_TDNFDownloadFile(
35
+     PTDNF pTdnf,
36
+     const char *pszRepo,
37
+     const char *pszFileUrl,
38
+@@ -209,6 +210,57 @@
39
+ }
40
+ 
41
+ uint32_t
42
++TDNFDownloadFile(
43
++    PTDNF pTdnf,
44
++    const char *pszRepo,
45
++    const char *pszFileUrl,
46
++    const char *pszFile,
47
++    const char *pszProgressData
48
++    )
49
++{
50
++    uint32_t dwError = 0;
51
++    int nRetriesLeft = 10;
52
++    char *pszRetry = NULL;
53
++
54
++    if(!pTdnf ||
55
++       !pTdnf->pArgs ||
56
++       IsNullOrEmptyString(pszFileUrl) ||
57
++       IsNullOrEmptyString(pszFile))
58
++    {
59
++        dwError = ERROR_TDNF_INVALID_PARAMETER;
60
++        BAIL_ON_TDNF_ERROR(dwError);
61
++    }
62
++
63
++    dwError = TDNFGetOptValue(pTdnf, "retry", &pszRetry);
64
++    BAIL_ON_TDNF_ERROR(dwError);
65
++
66
++    if (!IsNullOrEmptyString(pszRetry))
67
++    {
68
++        nRetriesLeft = atoi(pszRetry);
69
++    }
70
++
71
++retry:
72
++    dwError = _TDNFDownloadFile(
73
++                  pTdnf,
74
++                  pszRepo,
75
++                  pszFileUrl,
76
++                  pszFile,
77
++                  pszProgressData);
78
++    if (TDNFIsCurlError(dwError) && nRetriesLeft > 0)
79
++    {
80
++        fprintf(stdout, "Download error: %d. Retrying\n", dwError);
81
++        sleep(1);
82
++        --nRetriesLeft;
83
++        goto retry;
84
++    }
85
++    BAIL_ON_TDNF_ERROR(dwError);
86
++
87
++error:
88
++    TDNF_SAFE_FREE_MEMORY(pszRetry);
89
++    return dwError;
90
++}
91
++
92
++uint32_t
93
+ TDNFDownloadPackage(
94
+     PTDNF pTdnf,
95
+     HyPackage hPkg,
96
+diff --git a/client/utils.c b/client/utils.c
97
+index 8e0d5ec..70d93d7 100644
98
+--- a/client/utils.c
99
+@@ -611,3 +611,53 @@
100
+     TDNF_SAFE_FREE_MEMORY(pszPath);
101
+     goto cleanup;
102
+ }
103
++
104
++uint32_t
105
++TDNFGetOptValue(
106
++    PTDNF pTdnf,
107
++    const char *pszKey,
108
++    char **ppszValue
109
++    )
110
++{
111
++    uint32_t dwError = 0;
112
++    char *pszValue = NULL;
113
++    PTDNF_CMD_OPT pSetOpt = NULL;
114
++
115
++    if (!pTdnf || IsNullOrEmptyString(pszKey) || !ppszValue)
116
++    {
117
++        dwError = ERROR_TDNF_INVALID_PARAMETER;
118
++        BAIL_ON_TDNF_ERROR(dwError);
119
++    }
120
++
121
++    pSetOpt = pTdnf->pArgs->pSetOpt;
122
++
123
++    while(pSetOpt)
124
++    {
125
++        if(pSetOpt->nType == CMDOPT_KEYVALUE &&
126
++           !strcasecmp(pSetOpt->pszOptName, pszKey))
127
++        {
128
++            dwError = TDNFAllocateString(pSetOpt->pszOptValue, &pszValue);
129
++            BAIL_ON_TDNF_ERROR(dwError);
130
++
131
++            break;
132
++        }
133
++
134
++        pSetOpt = pSetOpt->pNext;
135
++    }
136
++
137
++    if (pszValue)
138
++    {
139
++        *ppszValue = pszValue;
140
++    }
141
++
142
++cleanup:
143
++    return dwError;
144
++
145
++error:
146
++    if(ppszValue)
147
++    {
148
++        *ppszValue = NULL;
149
++    }
150
++    TDNF_SAFE_FREE_MEMORY(pszValue);
151
++    goto cleanup;
152
++}
153
+diff --git a/tools/cli/defines.h b/tools/cli/defines.h
154
+index 58b9f42..05c759d 100644
155
+--- a/tools/cli/defines.h
156
+@@ -24,6 +24,7 @@
157
+ 
158
+ #define ENABLEREPO        "enablerepo"
159
+ #define DISABLEREPO       "disablerepo"
160
++#define RETRY             "retry"
161
+ 
162
+ #define IsNullOrEmptyString(str) (!(str) || !(*str))
163
+ 
164
+diff --git a/tools/cli/lib/parseargs.c b/tools/cli/lib/parseargs.c
165
+index 2a618fb..40cb73b 100644
166
+--- a/tools/cli/lib/parseargs.c
167
+@@ -53,6 +53,7 @@
168
+     {"exclude",       required_argument, 0, 0},            //--exclude
169
+     {"security",      no_argument, 0, 0},                  //--security
170
+     {"sec-severity",  required_argument, 0, 0},            //--sec-severity
171
++    {"retry",         required_argument, 0, 0},            //--retry
172
+     {0, 0, 0, 0}
173
+ };
174
+ 
175
+@@ -347,6 +348,15 @@
176
+         dwError = AddSetOpt(pCmdArgs, optarg);
177
+         BAIL_ON_CLI_ERROR(dwError);
178
+     }
179
++    else if(!strcasecmp(pszName, RETRY))
180
++    {
181
++        dwError = AddSetOptWithValues(
182
++                      pCmdArgs,
183
++                      CMDOPT_KEYVALUE,
184
++                      pszName,
185
++                      optarg);
186
++        BAIL_ON_CLI_ERROR(dwError);
187
++    }
188
+ cleanup:
189
+     if(pszCopyArgs)
190
+     {