-rw-r--r-- | cache.c | 4 | ||||
-rw-r--r-- | cgit.c | 4 |
2 files changed, 8 insertions, 0 deletions
@@ -24,48 +24,52 @@ void cache_prepare(struct cacheitem *item) cgit_query_repo, cgit_query_page, cgit_querystring)); if (cgit_query_has_symref) item->ttl = cgit_cache_dynamic_ttl; else if (cgit_query_has_sha1) item->ttl = cgit_cache_static_ttl; else item->ttl = cgit_cache_repo_ttl; } } int cache_exist(struct cacheitem *item) { if (stat(item->name, &item->st)) { item->st.st_mtime = 0; return 0; } return 1; } int cache_create_dirs() { char *path; + path = fmt("%s", cgit_cache_root); + if (mkdir(path, S_IRWXU) && errno!=EEXIST) + return 0; + if (!cgit_query_repo) return 0; path = fmt("%s/%s", cgit_cache_root, cgit_query_repo); if (mkdir(path, S_IRWXU) && errno!=EEXIST) return 0; if (cgit_query_page) { path = fmt("%s/%s/%s", cgit_cache_root, cgit_query_repo, cgit_query_page); if (mkdir(path, S_IRWXU) && errno!=EEXIST) return 0; } return 1; } int cache_refill_overdue(const char *lockfile) { struct stat st; if (stat(lockfile, &st)) return 0; else return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); @@ -21,54 +21,58 @@ static void cgit_print_repo_page(struct cacheitem *item) strerror(errno))); cgit_print_docend(); return; } setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); cgit_print_docstart(title, item); cgit_print_pageheader(title); if (!cgit_query_page) { cgit_print_summary(); } else if (!strcmp(cgit_query_page, "log")) { cgit_print_log(cgit_query_head, cgit_query_ofs, 100); } else if (!strcmp(cgit_query_page, "tree")) { cgit_print_tree(cgit_query_sha1); } else if (!strcmp(cgit_query_page, "commit")) { cgit_print_commit(cgit_query_sha1); } else if (!strcmp(cgit_query_page, "view")) { cgit_print_view(cgit_query_sha1); } cgit_print_docend(); } static void cgit_fill_cache(struct cacheitem *item) { + static char buf[PATH_MAX]; + + getcwd(buf, sizeof(buf)); htmlfd = item->fd; item->st.st_mtime = time(NULL); if (cgit_query_repo) cgit_print_repo_page(item); else cgit_print_repolist(item); + chdir(buf); } static void cgit_check_cache(struct cacheitem *item) { int i = 0; cache_prepare(item); top: if (++i > cgit_max_lock_attempts) { die("cgit_refresh_cache: unable to lock %s: %s", item->name, strerror(errno)); } if (!cache_exist(item)) { if (!cache_lock(item)) { sleep(1); goto top; } if (!cache_exist(item)) { cgit_fill_cache(item); cache_unlock(item); } else { cache_cancel_lock(item); } } else if (cache_expired(item) && cache_lock(item)) { |