|
diff --git a/cache.c b/cache.c index 2ed0d6f..7860fc7 100644 --- a/ cache.c+++ b/ cache.c |
|
@@ -27,60 +27,60 @@ char *cache_safe_filename(const char *unsafe) |
27 | c = '_'; |
27 | c = '_'; |
28 | *s++ = c; |
28 | *s++ = c; |
29 | } |
29 | } |
30 | *s = '\0'; |
30 | *s = '\0'; |
31 | return buf[bufidx]; |
31 | return buf[bufidx]; |
32 | } |
32 | } |
33 | |
33 | |
34 | int cache_exist(struct cacheitem *item) |
34 | int cache_exist(struct cacheitem *item) |
35 | { |
35 | { |
36 | if (stat(item->name, &item->st)) { |
36 | if (stat(item->name, &item->st)) { |
37 | item->st.st_mtime = 0; |
37 | item->st.st_mtime = 0; |
38 | return 0; |
38 | return 0; |
39 | } |
39 | } |
40 | return 1; |
40 | return 1; |
41 | } |
41 | } |
42 | |
42 | |
43 | int cache_create_dirs() |
43 | int cache_create_dirs() |
44 | { |
44 | { |
45 | char *path; |
45 | char *path; |
46 | |
46 | |
47 | path = fmt("%s", ctx.cfg.cache_root); |
47 | path = fmt("%s", ctx.cfg.cache_root); |
48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
49 | return 0; |
49 | return 0; |
50 | |
50 | |
51 | if (!cgit_repo) |
51 | if (!ctx.repo) |
52 | return 0; |
52 | return 0; |
53 | |
53 | |
54 | path = fmt("%s/%s", ctx.cfg.cache_root, |
54 | path = fmt("%s/%s", ctx.cfg.cache_root, |
55 | cache_safe_filename(cgit_repo->url)); |
55 | cache_safe_filename(ctx.repo->url)); |
56 | |
56 | |
57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
58 | return 0; |
58 | return 0; |
59 | |
59 | |
60 | if (ctx.qry.page) { |
60 | if (ctx.qry.page) { |
61 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, |
61 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, |
62 | cache_safe_filename(cgit_repo->url), |
62 | cache_safe_filename(ctx.repo->url), |
63 | ctx.qry.page); |
63 | ctx.qry.page); |
64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
65 | return 0; |
65 | return 0; |
66 | } |
66 | } |
67 | return 1; |
67 | return 1; |
68 | } |
68 | } |
69 | |
69 | |
70 | int cache_refill_overdue(const char *lockfile) |
70 | int cache_refill_overdue(const char *lockfile) |
71 | { |
71 | { |
72 | struct stat st; |
72 | struct stat st; |
73 | |
73 | |
74 | if (stat(lockfile, &st)) |
74 | if (stat(lockfile, &st)) |
75 | return 0; |
75 | return 0; |
76 | else |
76 | else |
77 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); |
77 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); |
78 | } |
78 | } |
79 | |
79 | |
80 | int cache_lock(struct cacheitem *item) |
80 | int cache_lock(struct cacheitem *item) |
81 | { |
81 | { |
82 | int i = 0; |
82 | int i = 0; |
83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
84 | |
84 | |
85 | top: |
85 | top: |
86 | if (++i > ctx.cfg.max_lock_attempts) |
86 | if (++i > ctx.cfg.max_lock_attempts) |
|