summaryrefslogtreecommitdiffabout
path: root/cgit.c
Side-by-side diff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/cgit.c b/cgit.c
index 110face..7f14016 100644
--- a/cgit.c
+++ b/cgit.c
@@ -444,62 +444,62 @@ static void cgit_print_repo_page()
cgit_print_docstart(title);
cgit_print_pageheader(title);
if (!cgit_query_page)
cgit_print_repo_summary();
else if (!strcmp(cgit_query_page, "log")) {
cgit_print_log(cgit_query_head, 0, 100);
} else if (!strcmp(cgit_query_page, "view")) {
cgit_print_object(cgit_query_sha1);
}
cgit_print_docend();
}
static void cgit_fill_cache(struct cacheitem *item)
{
htmlfd = item->fd;
item->st.st_mtime = time(NULL);
if (cgit_query_repo)
cgit_print_repo_page();
else
cgit_print_repolist();
}
static void cgit_refresh_cache(struct cacheitem *item)
{
+ cache_prepare(item);
top:
- if (!cache_lookup(item)) {
- if (cache_lock(item)) {
- cgit_fill_cache(item);
- cache_unlock(item);
- } else {
+ if (!cache_exist(item)) {
+ if (!cache_lock(item)) {
sched_yield();
goto top;
}
- } else if (cache_expired(item)) {
- if (cache_lock(item)) {
+ if (!cache_exist(item))
cgit_fill_cache(item);
- cache_unlock(item);
- }
+ cache_unlock(item);
+ } else if (cache_expired(item) && cache_lock(item)) {
+ if (cache_expired(item))
+ cgit_fill_cache(item);
+ cache_unlock(item);
}
}
static void cgit_print_cache(struct cacheitem *item)
{
static char buf[4096];
ssize_t i;
int fd = open(item->name, O_RDONLY);
if (fd<0)
die("Unable to open cached file %s", item->name);
while((i=read(fd, buf, sizeof(buf))) > 0)
write(STDOUT_FILENO, buf, i);
close(fd);
}
int main(int argc, const char **argv)
{
cgit_read_config("/etc/cgitrc", cgit_global_config_cb);
cgit_querystring = xstrdup(getenv("QUERY_STRING"));
cgit_parse_query(cgit_querystring, cgit_querystring_cb);
cgit_refresh_cache(&cacheitem);