|
diff --git a/cache.c b/cache.c index 372e38d..89f7ecd 100644 --- a/ cache.c+++ b/ cache.c |
|
@@ -6,8 +6,9 @@ |
6 | * (see COPYING for full license text) |
6 | * (see COPYING for full license text) |
7 | */ |
7 | */ |
8 | |
8 | |
9 | #include "cgit.h" |
9 | #include "cgit.h" |
| |
10 | #include "cache.h" |
10 | |
11 | |
11 | const int NOLOCK = -1; |
12 | const int NOLOCK = -1; |
12 | |
13 | |
13 | char *cache_safe_filename(const char *unsafe) |
14 | char *cache_safe_filename(const char *unsafe) |
@@ -43,25 +44,25 @@ int cache_exist(struct cacheitem *item) |
43 | int cache_create_dirs() |
44 | int cache_create_dirs() |
44 | { |
45 | { |
45 | char *path; |
46 | char *path; |
46 | |
47 | |
47 | path = fmt("%s", cgit_cache_root); |
48 | path = fmt("%s", ctx.cfg.cache_root); |
48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
49 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
49 | return 0; |
50 | return 0; |
50 | |
51 | |
51 | if (!cgit_repo) |
52 | if (!ctx.repo) |
52 | return 0; |
53 | return 0; |
53 | |
54 | |
54 | path = fmt("%s/%s", cgit_cache_root, |
55 | path = fmt("%s/%s", ctx.cfg.cache_root, |
55 | cache_safe_filename(cgit_repo->url)); |
56 | cache_safe_filename(ctx.repo->url)); |
56 | |
57 | |
57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
58 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
58 | return 0; |
59 | return 0; |
59 | |
60 | |
60 | if (cgit_query_page) { |
61 | if (ctx.qry.page) { |
61 | path = fmt("%s/%s/%s", cgit_cache_root, |
62 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, |
62 | cache_safe_filename(cgit_repo->url), |
63 | cache_safe_filename(ctx.repo->url), |
63 | cgit_query_page); |
64 | ctx.qry.page); |
64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
65 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
65 | return 0; |
66 | return 0; |
66 | } |
67 | } |
67 | return 1; |
68 | return 1; |
@@ -73,18 +74,18 @@ int cache_refill_overdue(const char *lockfile) |
73 | |
74 | |
74 | if (stat(lockfile, &st)) |
75 | if (stat(lockfile, &st)) |
75 | return 0; |
76 | return 0; |
76 | else |
77 | else |
77 | return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); |
78 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); |
78 | } |
79 | } |
79 | |
80 | |
80 | int cache_lock(struct cacheitem *item) |
81 | int cache_lock(struct cacheitem *item) |
81 | { |
82 | { |
82 | int i = 0; |
83 | int i = 0; |
83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
84 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
84 | |
85 | |
85 | top: |
86 | top: |
86 | if (++i > cgit_max_lock_attempts) |
87 | if (++i > ctx.cfg.max_lock_attempts) |
87 | die("cache_lock: unable to lock %s: %s", |
88 | die("cache_lock: unable to lock %s: %s", |
88 | item->name, strerror(errno)); |
89 | item->name, strerror(errno)); |
89 | |
90 | |
90 | item->fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); |
91 | item->fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); |
|