@@ -76,73 +76,24 @@ static int finalize_pack_download(const char *module, int newversion, const char
7676 return err ;
7777}
7878
79- static void download_free_data (void * data )
80- {
81- struct pack_data * pack_data = data ;
82-
83- if (!data ) {
84- return ;
85- }
86-
87- FREE (pack_data -> url );
88- FREE (pack_data -> filename );
89- FREE (pack_data );
90- }
91-
92- static bool download_error (enum download_status status , void * data )
93- {
94- struct pack_data * pack_data = data ;
95-
96- if (!data ) {
97- return false;
98- }
99-
100- if (status == DOWNLOAD_STATUS_NOT_FOUND ) {
101-
102- enum telemetry_severity level = TELEMETRY_LOW ;
103-
104- // Missing zero packs is a critical problem
105- if (pack_data -> oldversion == 0 ) {
106- level = TELEMETRY_CRIT ;
107- }
108- telemetry (level , "packmissing" , "url=%s\n" , pack_data -> url );
109- return true;
110- }
111-
112- return false;
113- }
114-
115- static bool download_successful (void * data )
116- {
117- struct pack_data * pack_data = data ;
118-
119- if (!pack_data ) {
120- return false;
121- }
122-
123- return finalize_pack_download (pack_data -> module , pack_data -> newversion , pack_data -> filename ) == 0 ;
124- }
125-
126- static int download_pack (struct swupd_curl_parallel_handle * download_handle , int oldversion , int newversion , char * module )
79+ static int download_pack (int oldversion , int newversion , char * module )
12780{
12881 char * url = NULL ;
12982 char * filename ;
83+ int ret ;
13084
13185 filename = statedir_get_delta_pack (module , oldversion , newversion );
13286
133- struct pack_data * pack_data ;
134-
13587 string_or_die (& url , "%s/%i/pack-%s-from-%i.tar" , globals .content_url , newversion , module , oldversion );
13688
137- pack_data = malloc_or_die (sizeof (struct pack_data ));
138-
139- pack_data -> url = url ;
140- pack_data -> filename = filename ;
141- pack_data -> module = module ;
142- pack_data -> newversion = newversion ;
143- pack_data -> oldversion = oldversion ;
89+ ret = swupd_curl_get_file (url , filename );
90+ FREE (url );
91+ if (!ret ) {
92+ ret = finalize_pack_download (module , newversion , filename );
93+ }
94+ FREE (filename );
14495
145- return swupd_curl_parallel_download_enqueue ( download_handle , url , filename , NULL , pack_data ) ;
96+ return ret ;
14697}
14798
14899static double packs_query_total_download_size (struct list * subs , struct manifest * mom )
@@ -224,7 +175,6 @@ int download_subscribed_packs(struct list *subs, struct manifest *mom, bool requ
224175 int err ;
225176 int list_length ;
226177 int complete = 0 ;
227- struct swupd_curl_parallel_handle * download_handle ;
228178 char * packs_size ;
229179
230180 progress_next_step ("download_packs" , PROGRESS_BAR );
@@ -263,20 +213,9 @@ int download_subscribed_packs(struct list *subs, struct manifest *mom, bool requ
263213 goto out ;
264214 }
265215
266- /* we need to download some files, so set up curl */
267- download_handle = swupd_curl_parallel_download_start (get_max_xfer (MAX_XFER ));
268- if (!download_handle ) {
269- list_free_list (need_download );
270- ret = -1 ;
271- goto out ;
272- }
273- swupd_curl_parallel_download_set_callbacks (download_handle , download_successful , download_error , download_free_data );
274-
275216 /* get size of the packs to download */
276217 download_progress .total_download_size = packs_query_total_download_size (need_download , mom );
277- if (download_progress .total_download_size > 0 ) {
278- swupd_curl_parallel_download_set_progress_callback (download_handle , swupd_progress_callback , & download_progress );
279- } else {
218+ if (download_progress .total_download_size <= 0 ) {
280219 debug ("Couldn't get the size of the packs to download, using number of packs instead\n" );
281220 download_progress .total_download_size = 0 ;
282221 }
@@ -298,13 +237,12 @@ int download_subscribed_packs(struct list *subs, struct manifest *mom, bool requ
298237 bundle = mom_search_bundle (mom , sub -> component );
299238 if (!bundle ) {
300239 debug ("The manifest for bundle %s was not found in the MoM\n" , sub -> component );
301- swupd_curl_parallel_download_cancel (download_handle );
302240
303241 ret = - SWUPD_INVALID_BUNDLE ;
304242 goto out ;
305243 }
306244
307- err = download_pack (download_handle , sub -> oldversion , sub -> version , sub -> component );
245+ err = download_pack (sub -> oldversion , sub -> version , sub -> component );
308246
309247 /* fall back for progress reporting when the download size
310248 * could not be determined */
@@ -313,7 +251,6 @@ int download_subscribed_packs(struct list *subs, struct manifest *mom, bool requ
313251 progress_report (complete , list_length );
314252 }
315253 if (err < 0 && required ) {
316- swupd_curl_parallel_download_cancel (download_handle );
317254 ret = err ;
318255 goto out ;
319256 }
@@ -322,9 +259,10 @@ int download_subscribed_packs(struct list *subs, struct manifest *mom, bool requ
322259 info ("Finishing packs extraction...\n" );
323260
324261 progress_next_step ("extract_packs" , PROGRESS_UNDEFINED );
325- return swupd_curl_parallel_download_end ( download_handle , NULL ) ;
262+ return ret ;
326263
327264out :
265+ list_free_list (need_download );
328266 progress_next_step ("extract_packs" , PROGRESS_UNDEFINED );
329267 return ret ;
330268}
0 commit comments