Skip to content

Commit 4f878ca

Browse files
committed
updated LinkTable invalidation
1 parent a5a5344 commit 4f878ca

File tree

2 files changed

+53
-57
lines changed

2 files changed

+53
-57
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- The refreshed LinkTable is now saved
11+
(https://github.com/fangfufu/httpdirfs/issues/141).
12+
- Only one LinkTable of the same directory is created when the cache mode is
13+
enabled (https://github.com/fangfufu/httpdirfs/issues/140).
14+
- Cache mode noe works correctly witht escaped URL
15+
(https://github.com/fangfufu/httpdirfs/issues/138).
16+
17+
## Changed
18+
- Improved LinkTable caching. LinkTable invalidation is now purely based on
19+
timeout.
20+
921
## [1.2.5] - 2023-02-24
1022

1123
### Fixed

src/link.c

Lines changed: 41 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -571,31 +571,14 @@ LinkTable *LinkTable_alloc(const char *url)
571571

572572
LinkTable *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,57 @@ 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+
LinkTable *linktbl = LinkTable_alloc(url);
611+
linktbl->index_time = time(NULL);
612+
lprintf(debug, "linktbl->index_time: %d\n", linktbl->index_time);
613+
637614
/*
638-
* Fill in the link table
639-
*/
640-
LinkTable_fill(linktbl);
641-
} else {
615+
* start downloading the base URL
616+
*/
617+
TransferStruct ts = Link_download_full(linktbl->links[0]);
618+
if (ts.curr_size == 0) {
619+
LinkTable_free(linktbl);
620+
return NULL;
621+
}
622+
642623
/*
643-
* Fill in the holes in the link table
644-
*/
645-
LinkTable_invalid_reset(linktbl);
646-
LinkTable_uninitialised_fill(linktbl);
647-
}
624+
* Otherwise parsed the received data
625+
*/
626+
GumboOutput *output = gumbo_parse(ts.data);
627+
HTML_to_LinkTable(url, output->root, linktbl);
628+
gumbo_destroy_output(&kGumboDefaultOptions, output);
629+
FREE(ts.data);
648630

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");
631+
LinkTable_fill(linktbl);
632+
633+
/*
634+
* Save the link table
635+
*/
636+
if (CACHE_SYSTEM_INIT) {
637+
if (LinkTable_disk_save(linktbl, unescaped_path)) {
638+
lprintf(error, "Failed to save the LinkTable!\n");
639+
}
655640
}
656641
}
657-
free(unescaped_path);
658642

659643
#ifdef DEBUG
660644
static int i = 0;
661645
lprintf(debug, "!!!!Calling LinkTable_new for the %d time!!!!\n", i);
662646
i++;
663647
#endif
664-
648+
free(unescaped_path);
665649
LinkTable_print(linktbl);
666-
667650
return linktbl;
668651
}
669652

@@ -791,8 +774,9 @@ LinkTable *LinkTable_disk_open(const char *dirn)
791774
lprintf(error,
792775
"cannot close the file pointer, %s\n", strerror(errno));
793776
}
794-
return linktbl;
777+
795778
FREE(path);
779+
return linktbl;
796780
}
797781

798782
LinkTable *path_to_Link_LinkTable_new(const char *path)

0 commit comments

Comments
 (0)