@@ -660,6 +660,14 @@ static void LinkTable_disk_delete(const char *dirn)
660
660
FREE (metadirn );
661
661
}
662
662
663
+ /* This is necessary to get the compiler on some platforms to stop
664
+ complaining about the fact that we're not using the return value of
665
+ fread, when we know we aren't and that's fine. */
666
+ static inline void ignore_value (int i )
667
+ {
668
+ (void ) i ;
669
+ }
670
+
663
671
int LinkTable_disk_save (LinkTable * linktbl , const char * dirn )
664
672
{
665
673
char * metadirn = path_append (META_DIR , dirn );
@@ -673,16 +681,19 @@ int LinkTable_disk_save(LinkTable *linktbl, const char *dirn)
673
681
FREE (path );
674
682
return -1 ;
675
683
}
676
- FREE (path );
677
684
678
- fwrite (& linktbl -> num , sizeof (int ), 1 , fp );
685
+ if (fwrite (& linktbl -> num , sizeof (int ), 1 , fp ) != 1 ||
686
+ fwrite (& linktbl -> index_time , sizeof (time ), 1 , fp ) != 1 ) {
687
+ lprintf (error , "Failed to save the header of %s!\n" , path );
688
+ }
689
+ FREE (path );
679
690
for (int i = 0 ; i < linktbl -> num ; i ++ ) {
680
- fwrite (linktbl -> links [i ]-> linkname , sizeof (char ),
681
- MAX_FILENAME_LEN , fp );
682
- fwrite (linktbl -> links [i ]-> f_url , sizeof (char ), MAX_PATH_LEN , fp );
683
- fwrite (& linktbl -> links [i ]-> type , sizeof (LinkType ), 1 , fp );
684
- fwrite (& linktbl -> links [i ]-> content_length , sizeof (size_t ), 1 , fp );
685
- fwrite (& linktbl -> links [i ]-> time , sizeof (long ), 1 , fp );
691
+ ignore_value ( fwrite (linktbl -> links [i ]-> linkname , sizeof (char ),
692
+ MAX_FILENAME_LEN , fp )) ;
693
+ ignore_value ( fwrite (linktbl -> links [i ]-> f_url , sizeof (char ), MAX_PATH_LEN , fp ) );
694
+ ignore_value ( fwrite (& linktbl -> links [i ]-> type , sizeof (LinkType ), 1 , fp ) );
695
+ ignore_value ( fwrite (& linktbl -> links [i ]-> content_length , sizeof (size_t ), 1 , fp ) );
696
+ ignore_value ( fwrite (& linktbl -> links [i ]-> time , sizeof (long ), 1 , fp ) );
686
697
}
687
698
688
699
int res = 0 ;
@@ -701,14 +712,6 @@ int LinkTable_disk_save(LinkTable *linktbl, const char *dirn)
701
712
return res ;
702
713
}
703
714
704
- /* This is necessary to get the compiler on some platforms to stop
705
- complaining about the fact that we're not using the return value of
706
- fread, when we know we aren't and that's fine. */
707
- static inline void ignore_value (int i )
708
- {
709
- (void ) i ;
710
- }
711
-
712
715
LinkTable * LinkTable_disk_open (const char * dirn )
713
716
{
714
717
char * metadirn = path_append (META_DIR , dirn );
@@ -729,10 +732,12 @@ LinkTable *LinkTable_disk_open(const char *dirn)
729
732
730
733
LinkTable * linktbl = CALLOC (1 , sizeof (LinkTable ));
731
734
732
- if (fread (& linktbl -> num , sizeof (int ), 1 , fp ) != 1 ) {
733
- lprintf (error , "Failed to read the first int of %s!\n" , path );
735
+ if (fread (& linktbl -> num , sizeof (int ), 1 , fp ) != 1 ||
736
+ fread (& linktbl -> index_time , sizeof (time ), 1 , fp ) != 1 ) {
737
+ lprintf (error , "Failed to read the header of %s!\n" , path );
734
738
LinkTable_free (linktbl );
735
739
LinkTable_disk_delete (dirn );
740
+ FREE (path );
736
741
return NULL ;
737
742
}
738
743
linktbl -> links = CALLOC (linktbl -> num , sizeof (Link * ));
@@ -749,16 +754,13 @@ LinkTable *LinkTable_disk_open(const char *dirn)
749
754
sizeof (size_t ), 1 , fp ));
750
755
ignore_value (fread (& linktbl -> links [i ]-> time , sizeof (long ), 1 , fp ));
751
756
if (feof (fp )) {
752
- /*
753
- * reached EOF
754
- */
755
- lprintf (error , "reached EOF!\n" );
757
+ lprintf (error , "Corrupted LinkTable!\n" );
756
758
LinkTable_free (linktbl );
757
759
LinkTable_disk_delete (dirn );
758
760
return NULL ;
759
761
}
760
762
if (ferror (fp )) {
761
- lprintf (error , "encountered ferror!\n" );
763
+ lprintf (error , "Encountered ferror!\n" );
762
764
LinkTable_free (linktbl );
763
765
LinkTable_disk_delete (dirn );
764
766
return NULL ;
@@ -769,6 +771,7 @@ LinkTable *LinkTable_disk_open(const char *dirn)
769
771
"cannot close the file pointer, %s\n" , strerror (errno ));
770
772
}
771
773
return linktbl ;
774
+ FREE (path );
772
775
}
773
776
774
777
LinkTable * path_to_Link_LinkTable_new (const char * path )
@@ -790,6 +793,9 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
790
793
time_t time_now = time (NULL );
791
794
if (time_now - next_table -> index_time > CONFIG .refresh_timeout ) {
792
795
/* refresh directory contents */
796
+ lprintf (info , "%d, %d\n" , time_now , next_table -> index_time )
797
+ lprintf (info , "%d, %d\n" , time_now - next_table -> index_time , CONFIG .refresh_timeout );
798
+ lprintf (info , "Refreshing LinkTable for %s\n" , path );
793
799
LinkTable_free (next_table );
794
800
next_table = NULL ;
795
801
if (link ) {
0 commit comments