3636
3737#include "tools.h"
3838#include "pkgin.h"
39- #include <archive.h>
40- #include <archive_entry.h>
4139
4240static const struct Summary {
4341 const int type ;
@@ -86,6 +84,7 @@ static void freecols(void);
8684static void free_insertlist (void );
8785static void insert_local_summary (FILE * );
8886static void insert_remote_summary (struct archive * , char * );
87+ static void delete_remote_tbl (struct Summary , char * );
8988static void prepare_insert (int , struct Summary );
9089int colnames (void * , int , char * * , char * * );
9190
@@ -98,15 +97,14 @@ int force_fetch = 0;
9897static const char * const sumexts [] = { "bz2" , "gz" , NULL };
9998
10099/*
101- * Download a remote summary into memory and return an open
102- * libarchive handler to it.
100+ * Open a remote summary and return an open libarchive handler to it.
103101 */
104102static struct archive *
105103fetch_summary (char * cur_repo )
106104{
107105 struct archive * a ;
108106 struct archive_entry * ae ;
109- Dlfile * file = NULL ;
107+ Sumfile * sum = NULL ;
110108 time_t sum_mtime ;
111109 int i ;
112110 char buf [BUFSIZ ];
@@ -120,14 +118,14 @@ fetch_summary(char *cur_repo)
120118 snprintf (buf , BUFSIZ , "%s/%s.%s" ,
121119 cur_repo , PKG_SUMMARY , sumexts [i ]);
122120
123- if ((file = download_summary (buf , & sum_mtime )) != NULL )
121+ if ((sum = sum_open (buf , & sum_mtime )) != NULL )
124122 break ; /* pkg_summary found and not up-to-date */
125123
126124 if (sum_mtime < 0 ) /* pkg_summary found, but up-to-date */
127125 return NULL ;
128126 }
129127
130- if (file == NULL )
128+ if (sum == NULL )
131129 errx (EXIT_FAILURE , MSG_COULDNT_FETCH , buf );
132130
133131 pkgindb_dovaquery (UPDATE_REPO_MTIME , (long long )sum_mtime , cur_repo );
@@ -137,35 +135,17 @@ fetch_summary(char *cur_repo)
137135
138136 if (archive_read_support_filter_all (a ) != ARCHIVE_OK ||
139137 archive_read_support_format_raw (a ) != ARCHIVE_OK ||
140- archive_read_open_memory (a , file -> buf , file -> size ) != ARCHIVE_OK )
141- errx (EXIT_FAILURE , "Cannot open in-memory pkg_summary: %s" ,
138+ archive_read_open (a , sum , sum_start , sum_read , sum_close ) != ARCHIVE_OK )
139+ errx (EXIT_FAILURE , "Cannot open pkg_summary: %s" ,
142140 archive_error_string (a ));
143141
144142 if (archive_read_next_header (a , & ae ) != ARCHIVE_OK )
145- errx (EXIT_FAILURE , "Cannot read in-memory pkg_summary: %s" ,
143+ errx (EXIT_FAILURE , "Cannot read pkg_summary: %s" ,
146144 archive_error_string (a ));
147145
148146 return a ;
149147}
150148
151- /**
152- * progress percentage
153- */
154- static void
155- progress (char c )
156- {
157- const char * alnum = ALNUM ;
158- int i , alnumlen = strlen (alnum );
159- float percent = 0 ;
160-
161- for (i = 0 ; i < alnumlen ; i ++ )
162- if (c == alnum [i ])
163- percent = ((float )(i + 1 )/ (float )alnumlen ) * 100 ;
164-
165- printf (MSG_UPDATING_DB_PCT , (int )percent );
166- fflush (stdout );
167- }
168-
169149static void
170150freecols ()
171151{
@@ -278,11 +258,12 @@ parse_entry(struct Summary sum, int pkgid, char *line)
278258 if (check_machine_arch && strncmp (line , "MACHINE_ARCH=" , 13 ) == 0 ) {
279259 if (strncmp (CHECK_MACHINE_ARCH , val ,
280260 strlen (CHECK_MACHINE_ARCH ))) {
261+ alarm (0 ); /* Stop the progress meter */
281262 printf (MSG_ARCH_DONT_MATCH , val , CHECK_MACHINE_ARCH );
282263 if (!check_yesno (DEFAULT_NO ))
283264 exit (EXIT_FAILURE );
284265 check_machine_arch = 0 ;
285- printf ( "\r" MSG_UPDATING_DB );
266+ alarm ( 1 ); /* Restart progress XXX: UPDATE_INTERVAL */
286267 }
287268 return ;
288269 }
@@ -364,13 +345,6 @@ parse_entry(struct Summary sum, int pkgid, char *line)
364345 * v ++ = '\0' ;
365346 add_to_slist ("PKGNAME" , val );
366347 add_to_slist ("PKGVERS" , v );
367-
368- /*
369- * Update progress counter based on position
370- * in alphabet of first PKGNAME character.
371- */
372- if (!parsable )
373- progress (val [0 ]);
374348 } else
375349 add_to_slist (cols .name [i ], val );
376350
@@ -451,11 +425,6 @@ insert_remote_summary(struct archive *a, char *cur_repo)
451425
452426 pkgindb_doquery ("BEGIN;" , NULL , NULL );
453427
454- if (!parsable ) {
455- printf (MSG_UPDATING_DB );
456- fflush (stdout );
457- }
458-
459428 /*
460429 * Main loop. Read in archive, split into package records and parse
461430 * each entry, then insert packge. If we are in the middle of a
@@ -527,14 +496,11 @@ insert_remote_summary(struct archive *a, char *cur_repo)
527496
528497 pkgindb_doquery ("COMMIT;" , NULL , NULL );
529498
530- if (!parsable ) {
531- printf ("\n" );
532- fflush (stdout );
533- }
534-
535- if (r != ARCHIVE_OK )
499+ if (r != ARCHIVE_OK ) {
500+ delete_remote_tbl (sumsw [REMOTE_SUMMARY ], cur_repo );
536501 errx (EXIT_FAILURE , "Short read of pkg_summary: %s" ,
537502 archive_error_string (a ));
503+ }
538504
539505 archive_read_close (a );
540506}
@@ -685,6 +651,8 @@ update_remotedb(void)
685651 /* loop through PKG_REPOS */
686652 for (prepos = pkg_repos ; * prepos != NULL ; prepos ++ ) {
687653
654+ printf (MSG_PROCESSING_REMOTE_SUMMARY , * prepos );
655+
688656 /* load remote pkg_summary */
689657 if ((a = fetch_summary (* prepos )) == NULL ) {
690658 printf (MSG_DB_IS_UP_TO_DATE , * prepos );
@@ -701,8 +669,6 @@ update_remotedb(void)
701669 cleaned = 1 ;
702670 }
703671
704- printf (MSG_PROCESSING_REMOTE_SUMMARY , * prepos );
705-
706672 /* delete remote* associated to this repository */
707673 delete_remote_tbl (sumsw [REMOTE_SUMMARY ], * prepos );
708674 /* update remote* table for this repository */
0 commit comments