summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cache.c4
-rw-r--r--cgit.c4
2 files changed, 8 insertions, 0 deletions
diff --git a/cache.c b/cache.c
index 39e63a5..91b89a6 100644
--- a/cache.c
+++ b/cache.c
@@ -36,24 +36,28 @@ int cache_exist(struct cacheitem *item)
36{ 36{
37 if (stat(item->name, &item->st)) { 37 if (stat(item->name, &item->st)) {
38 item->st.st_mtime = 0; 38 item->st.st_mtime = 0;
39 return 0; 39 return 0;
40 } 40 }
41 return 1; 41 return 1;
42} 42}
43 43
44int cache_create_dirs() 44int cache_create_dirs()
45{ 45{
46 char *path; 46 char *path;
47 47
48 path = fmt("%s", cgit_cache_root);
49 if (mkdir(path, S_IRWXU) && errno!=EEXIST)
50 return 0;
51
48 if (!cgit_query_repo) 52 if (!cgit_query_repo)
49 return 0; 53 return 0;
50 54
51 path = fmt("%s/%s", cgit_cache_root, cgit_query_repo); 55 path = fmt("%s/%s", cgit_cache_root, cgit_query_repo);
52 if (mkdir(path, S_IRWXU) && errno!=EEXIST) 56 if (mkdir(path, S_IRWXU) && errno!=EEXIST)
53 return 0; 57 return 0;
54 58
55 if (cgit_query_page) { 59 if (cgit_query_page) {
56 path = fmt("%s/%s/%s", cgit_cache_root, cgit_query_repo, 60 path = fmt("%s/%s/%s", cgit_cache_root, cgit_query_repo,
57 cgit_query_page); 61 cgit_query_page);
58 if (mkdir(path, S_IRWXU) && errno!=EEXIST) 62 if (mkdir(path, S_IRWXU) && errno!=EEXIST)
59 return 0; 63 return 0;
diff --git a/cgit.c b/cgit.c
index 9dbc608..372b436 100644
--- a/cgit.c
+++ b/cgit.c
@@ -33,30 +33,34 @@ static void cgit_print_repo_page(struct cacheitem *item)
33 } else if (!strcmp(cgit_query_page, "tree")) { 33 } else if (!strcmp(cgit_query_page, "tree")) {
34 cgit_print_tree(cgit_query_sha1); 34 cgit_print_tree(cgit_query_sha1);
35 } else if (!strcmp(cgit_query_page, "commit")) { 35 } else if (!strcmp(cgit_query_page, "commit")) {
36 cgit_print_commit(cgit_query_sha1); 36 cgit_print_commit(cgit_query_sha1);
37 } else if (!strcmp(cgit_query_page, "view")) { 37 } else if (!strcmp(cgit_query_page, "view")) {
38 cgit_print_view(cgit_query_sha1); 38 cgit_print_view(cgit_query_sha1);
39 } 39 }
40 cgit_print_docend(); 40 cgit_print_docend();
41} 41}
42 42
43static void cgit_fill_cache(struct cacheitem *item) 43static void cgit_fill_cache(struct cacheitem *item)
44{ 44{
45 static char buf[PATH_MAX];
46
47 getcwd(buf, sizeof(buf));
45 htmlfd = item->fd; 48 htmlfd = item->fd;
46 item->st.st_mtime = time(NULL); 49 item->st.st_mtime = time(NULL);
47 if (cgit_query_repo) 50 if (cgit_query_repo)
48 cgit_print_repo_page(item); 51 cgit_print_repo_page(item);
49 else 52 else
50 cgit_print_repolist(item); 53 cgit_print_repolist(item);
54 chdir(buf);
51} 55}
52 56
53static void cgit_check_cache(struct cacheitem *item) 57static void cgit_check_cache(struct cacheitem *item)
54{ 58{
55 int i = 0; 59 int i = 0;
56 60
57 cache_prepare(item); 61 cache_prepare(item);
58 top: 62 top:
59 if (++i > cgit_max_lock_attempts) { 63 if (++i > cgit_max_lock_attempts) {
60 die("cgit_refresh_cache: unable to lock %s: %s", 64 die("cgit_refresh_cache: unable to lock %s: %s",
61 item->name, strerror(errno)); 65 item->name, strerror(errno));
62 } 66 }