@@ -571,31 +571,14 @@ LinkTable *LinkTable_alloc(const char *url)
571571
572572LinkTable * LinkTable_new (const char * url )
573573{
574- LinkTable * linktbl = LinkTable_alloc (url );
575- linktbl -> index_time = time (NULL );
576- lprintf (debug , "linktbl->index_time: %d\n" , linktbl -> index_time );
577-
578- /*
579- * start downloading the base URL
580- */
581- TransferStruct ts = Link_download_full (linktbl -> links [0 ]);
582- if (ts .curr_size == 0 ) {
583- LinkTable_free (linktbl );
584- return NULL ;
585- }
586-
587- /*
588- * Otherwise parsed the received data
589- */
590- GumboOutput * output = gumbo_parse (ts .data );
591- HTML_to_LinkTable (url , output -> root , linktbl );
592- gumbo_destroy_output (& kGumboDefaultOptions , output );
593- FREE (ts .data );
594-
595- int skip_fill = 0 ;
596574 char * unescaped_path ;
597575 unescaped_path =
598576 curl_easy_unescape (NULL , url + ROOT_LINK_OFFSET , 0 , NULL );
577+ LinkTable * linktbl = NULL ;
578+
579+ /*
580+ * Attempt to load the LinkTable from the disk.
581+ */
599582 if (CACHE_SYSTEM_INIT ) {
600583 CacheDir_create (unescaped_path );
601584 LinkTable * disk_linktbl ;
@@ -613,57 +596,56 @@ LinkTable *LinkTable_new(const char *url)
613596 time_now - disk_linktbl -> index_time ,
614597 CONFIG .refresh_timeout );
615598 LinkTable_free (disk_linktbl );
616- }
617- /*
618- * Check if there are inconsistencies for the on-disk LinkTable
619- */
620-
621- if (disk_linktbl -> num == linktbl -> num ) {
622- LinkTable_free (linktbl );
623- linktbl = disk_linktbl ;
624- skip_fill = 1 ;
625599 } else {
626- lprintf (info ,
627- "disk_linktbl->num: %d, linktbl->num: %d\n" ,
628- disk_linktbl -> num , linktbl -> num );
629- lprintf (info , "Refreshing LinkTable for %s\n" ,
630- url + ROOT_LINK_OFFSET );
631- LinkTable_free (disk_linktbl );
600+ linktbl = disk_linktbl ;
632601 }
633602 }
634603 }
635604
636- if (!skip_fill ) {
605+ /*
606+ * Download a new LinkTable because we didn't manange to load it from the
607+ * disk
608+ */
609+ if (!linktbl ) {
610+ linktbl -> index_time = time (NULL );
611+ lprintf (debug , "linktbl->index_time: %d\n" , linktbl -> index_time );
612+
637613 /*
638- * Fill in the link table
639- */
640- LinkTable_fill (linktbl );
641- } else {
614+ * start downloading the base URL
615+ */
616+ TransferStruct ts = Link_download_full (linktbl -> links [0 ]);
617+ if (ts .curr_size == 0 ) {
618+ LinkTable_free (linktbl );
619+ return NULL ;
620+ }
621+
642622 /*
643- * Fill in the holes in the link table
644- */
645- LinkTable_invalid_reset (linktbl );
646- LinkTable_uninitialised_fill (linktbl );
647- }
623+ * Otherwise parsed the received data
624+ */
625+ GumboOutput * output = gumbo_parse (ts .data );
626+ HTML_to_LinkTable (url , output -> root , linktbl );
627+ gumbo_destroy_output (& kGumboDefaultOptions , output );
628+ FREE (ts .data );
648629
649- /*
650- * Save the link table
651- */
652- if (CACHE_SYSTEM_INIT ) {
653- if (LinkTable_disk_save (linktbl , unescaped_path )) {
654- lprintf (error , "Failed to save the LinkTable!\n" );
630+ LinkTable_fill (linktbl );
631+
632+ /*
633+ * Save the link table
634+ */
635+ if (CACHE_SYSTEM_INIT ) {
636+ if (LinkTable_disk_save (linktbl , unescaped_path )) {
637+ lprintf (error , "Failed to save the LinkTable!\n" );
638+ }
655639 }
656640 }
657- free (unescaped_path );
658641
659642#ifdef DEBUG
660643 static int i = 0 ;
661644 lprintf (debug , "!!!!Calling LinkTable_new for the %d time!!!!\n" , i );
662645 i ++ ;
663646#endif
664-
647+ free ( unescaped_path );
665648 LinkTable_print (linktbl );
666-
667649 return linktbl ;
668650}
669651
@@ -791,8 +773,9 @@ LinkTable *LinkTable_disk_open(const char *dirn)
791773 lprintf (error ,
792774 "cannot close the file pointer, %s\n" , strerror (errno ));
793775 }
794- return linktbl ;
776+
795777 FREE (path );
778+ return linktbl ;
796779}
797780
798781LinkTable * path_to_Link_LinkTable_new (const char * path )
0 commit comments