blob: 2c70be784d6187cb63d20475e8c6df203b6bb31f [file] [log] [blame]
Lars Hjemli7640d902006-12-10 22:41:14 +01001/* cache.c: cache management
2 *
Lukas Fleischerf7f26f82014-01-08 15:10:49 +01003 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
Lars Hjemli7640d902006-12-10 22:41:14 +01004 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
Lars Hjemli939d32f2008-04-28 11:32:42 +02007 *
8 *
9 * The cache is just a directory structure where each file is a cache slot,
10 * and each filename is based on the hash of some key (e.g. the cgit url).
11 * Each file contains the full key followed by the cached content for that
12 * key.
13 *
Lars Hjemli7640d902006-12-10 22:41:14 +010014 */
15
Lars Hjemli25105d72006-12-10 22:31:36 +010016#include "cgit.h"
Lars Hjemliee4056b2008-03-27 09:22:13 +010017#include "cache.h"
John Keepingf32a2da2013-05-18 18:46:39 +010018#include "html.h"
John Keeping43620cf2015-08-13 12:14:17 +010019#ifdef HAVE_LINUX_SENDFILE
20#include <sys/sendfile.h>
21#endif
Lars Hjemli25105d72006-12-10 22:31:36 +010022
Lars Hjemli939d32f2008-04-28 11:32:42 +020023#define CACHE_BUFSIZE (1024 * 4)
Lars Hjemli25105d72006-12-10 22:31:36 +010024
Lars Hjemli939d32f2008-04-28 11:32:42 +020025struct cache_slot {
26 const char *key;
John Keeping3fbfced2016-01-16 11:03:06 +000027 size_t keylen;
Lars Hjemli939d32f2008-04-28 11:32:42 +020028 int ttl;
29 cache_fill_fn fn;
Lars Hjemli939d32f2008-04-28 11:32:42 +020030 int cache_fd;
31 int lock_fd;
John Keepingb31e9982018-06-20 07:29:14 +020032 int stdout_fd;
Lars Hjemli939d32f2008-04-28 11:32:42 +020033 const char *cache_name;
34 const char *lock_name;
35 int match;
36 struct stat cache_st;
Lars Hjemli939d32f2008-04-28 11:32:42 +020037 int bufsize;
38 char buf[CACHE_BUFSIZE];
39};
40
41/* Open an existing cache slot and fill the cache buffer with
42 * (part of) the content of the cache file. Return 0 on success
43 * and errno otherwise.
44 */
45static int open_slot(struct cache_slot *slot)
Lars Hjemli2c2047f2007-01-12 00:24:35 +010046{
Lars Hjemli939d32f2008-04-28 11:32:42 +020047 char *bufz;
John Keeping3fbfced2016-01-16 11:03:06 +000048 ssize_t bufkeylen = -1;
Lars Hjemli2c2047f2007-01-12 00:24:35 +010049
Lars Hjemli939d32f2008-04-28 11:32:42 +020050 slot->cache_fd = open(slot->cache_name, O_RDONLY);
51 if (slot->cache_fd == -1)
52 return errno;
Lars Hjemli72fa5c62007-05-18 03:54:15 +020053
Lars Hjemli939d32f2008-04-28 11:32:42 +020054 if (fstat(slot->cache_fd, &slot->cache_st))
55 return errno;
56
Lars Hjemlicdc6b2f2008-05-18 23:26:05 +020057 slot->bufsize = xread(slot->cache_fd, slot->buf, sizeof(slot->buf));
Lars Hjemli6102bcf2008-05-18 23:10:05 +020058 if (slot->bufsize < 0)
Lars Hjemli939d32f2008-04-28 11:32:42 +020059 return errno;
60
61 bufz = memchr(slot->buf, 0, slot->bufsize);
62 if (bufz)
63 bufkeylen = bufz - slot->buf;
64
John Keeping33bc9492016-01-16 11:03:07 +000065 if (slot->key)
66 slot->match = bufkeylen == slot->keylen &&
67 !memcmp(slot->key, slot->buf, bufkeylen + 1);
Lars Hjemli939d32f2008-04-28 11:32:42 +020068
69 return 0;
Lars Hjemli2c2047f2007-01-12 00:24:35 +010070}
71
Lars Hjemli939d32f2008-04-28 11:32:42 +020072/* Close the active cache slot */
Lars Hjemlid4028112008-05-18 23:16:50 +020073static int close_slot(struct cache_slot *slot)
Lars Hjemlif5069d82006-12-11 09:57:58 +010074{
Lars Hjemlid4028112008-05-18 23:16:50 +020075 int err = 0;
Lars Hjemli939d32f2008-04-28 11:32:42 +020076 if (slot->cache_fd > 0) {
Lars Hjemlid4028112008-05-18 23:16:50 +020077 if (close(slot->cache_fd))
78 err = errno;
79 else
80 slot->cache_fd = -1;
Lars Hjemli25105d72006-12-10 22:31:36 +010081 }
Lars Hjemlid4028112008-05-18 23:16:50 +020082 return err;
Lars Hjemli25105d72006-12-10 22:31:36 +010083}
84
Lars Hjemli939d32f2008-04-28 11:32:42 +020085/* Print the content of the active cache slot (but skip the key). */
86static int print_slot(struct cache_slot *slot)
Lars Hjemli25105d72006-12-10 22:31:36 +010087{
Sebastian Andrzej Siewiord3581b52014-01-18 21:24:58 +010088#ifdef HAVE_LINUX_SENDFILE
89 off_t start_off;
90 int ret;
91
92 start_off = slot->keylen + 1;
93
94 do {
95 ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off,
96 slot->cache_st.st_size - start_off);
97 if (ret < 0) {
98 if (errno == EAGAIN || errno == EINTR)
99 continue;
100 return errno;
101 }
102 return 0;
103 } while (1);
104#else
Lars Hjemlidd7c1722008-05-20 17:56:47 +0200105 ssize_t i, j;
Lars Hjemli25105d72006-12-10 22:31:36 +0100106
Lars Hjemli939d32f2008-04-28 11:32:42 +0200107 i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET);
108 if (i != slot->keylen + 1)
109 return errno;
110
Lars Hjemlidd7c1722008-05-20 17:56:47 +0200111 do {
112 i = j = xread(slot->cache_fd, slot->buf, sizeof(slot->buf));
113 if (i > 0)
114 j = xwrite(STDOUT_FILENO, slot->buf, i);
115 } while (i > 0 && j == i);
Lars Hjemli939d32f2008-04-28 11:32:42 +0200116
Lars Hjemlidd7c1722008-05-20 17:56:47 +0200117 if (i < 0 || j != i)
Lars Hjemli939d32f2008-04-28 11:32:42 +0200118 return errno;
119 else
Lars Hjemli7c849d92006-12-16 13:55:58 +0100120 return 0;
Sebastian Andrzej Siewiord3581b52014-01-18 21:24:58 +0100121#endif
Lars Hjemli25105d72006-12-10 22:31:36 +0100122}
123
Lars Hjemli939d32f2008-04-28 11:32:42 +0200124/* Check if the slot has expired */
125static int is_expired(struct cache_slot *slot)
126{
127 if (slot->ttl < 0)
128 return 0;
129 else
Lukas Fleischer53bc7472013-03-03 16:04:29 +0100130 return slot->cache_st.st_mtime + slot->ttl * 60 < time(NULL);
Lars Hjemli939d32f2008-04-28 11:32:42 +0200131}
132
133/* Check if the slot has been modified since we opened it.
134 * NB: If stat() fails, we pretend the file is modified.
135 */
136static int is_modified(struct cache_slot *slot)
Lars Hjemli318d1062006-12-11 12:10:12 +0100137{
138 struct stat st;
139
Lars Hjemli939d32f2008-04-28 11:32:42 +0200140 if (stat(slot->cache_name, &st))
141 return 1;
142 return (st.st_ino != slot->cache_st.st_ino ||
143 st.st_mtime != slot->cache_st.st_mtime ||
144 st.st_size != slot->cache_st.st_size);
145}
146
147/* Close an open lockfile */
Lars Hjemlid4028112008-05-18 23:16:50 +0200148static int close_lock(struct cache_slot *slot)
Lars Hjemli939d32f2008-04-28 11:32:42 +0200149{
Lars Hjemlid4028112008-05-18 23:16:50 +0200150 int err = 0;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200151 if (slot->lock_fd > 0) {
Lars Hjemlid4028112008-05-18 23:16:50 +0200152 if (close(slot->lock_fd))
153 err = errno;
154 else
155 slot->lock_fd = -1;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200156 }
Lars Hjemlid4028112008-05-18 23:16:50 +0200157 return err;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200158}
159
160/* Create a lockfile used to store the generated content for a cache
161 * slot, and write the slot key + \0 into it.
162 * Returns 0 on success and errno otherwise.
163 */
164static int lock_slot(struct cache_slot *slot)
165{
John Keepingdb9a70b2015-03-03 19:22:31 +0000166 struct flock lock = {
167 .l_type = F_WRLCK,
168 .l_whence = SEEK_SET,
169 .l_start = 0,
170 .l_len = 0,
171 };
172
173 slot->lock_fd = open(slot->lock_name, O_RDWR | O_CREAT,
Lukas Fleischer53bc7472013-03-03 16:04:29 +0100174 S_IRUSR | S_IWUSR);
Lars Hjemli939d32f2008-04-28 11:32:42 +0200175 if (slot->lock_fd == -1)
176 return errno;
John Keepingdb9a70b2015-03-03 19:22:31 +0000177 if (fcntl(slot->lock_fd, F_SETLK, &lock) < 0) {
178 int saved_errno = errno;
179 close(slot->lock_fd);
180 slot->lock_fd = -1;
181 return saved_errno;
182 }
Lars Hjemlicdc6b2f2008-05-18 23:26:05 +0200183 if (xwrite(slot->lock_fd, slot->key, slot->keylen + 1) < 0)
Lars Hjemlid4028112008-05-18 23:16:50 +0200184 return errno;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200185 return 0;
186}
187
188/* Release the current lockfile. If `replace_old_slot` is set the
189 * lockfile replaces the old cache slot, otherwise the lockfile is
190 * just deleted.
191 */
192static int unlock_slot(struct cache_slot *slot, int replace_old_slot)
193{
194 int err;
195
196 if (replace_old_slot)
197 err = rename(slot->lock_name, slot->cache_name);
Lars Hjemli318d1062006-12-11 12:10:12 +0100198 else
Lars Hjemli939d32f2008-04-28 11:32:42 +0200199 err = unlink(slot->lock_name);
Lars Hjemlid4028112008-05-18 23:16:50 +0200200
John Keepingb31e9982018-06-20 07:29:14 +0200201 /* Restore stdout and close the temporary FD. */
202 if (slot->stdout_fd >= 0) {
203 dup2(slot->stdout_fd, STDOUT_FILENO);
204 close(slot->stdout_fd);
205 slot->stdout_fd = -1;
206 }
207
Lars Hjemlid4028112008-05-18 23:16:50 +0200208 if (err)
209 return errno;
210
211 return 0;
Lars Hjemli318d1062006-12-11 12:10:12 +0100212}
213
Lars Hjemli939d32f2008-04-28 11:32:42 +0200214/* Generate the content for the current cache slot by redirecting
215 * stdout to the lock-fd and invoking the callback function
216 */
217static int fill_slot(struct cache_slot *slot)
Lars Hjemli25105d72006-12-10 22:31:36 +0100218{
Lars Hjemli939d32f2008-04-28 11:32:42 +0200219 /* Preserve stdout */
John Keepingb31e9982018-06-20 07:29:14 +0200220 slot->stdout_fd = dup(STDOUT_FILENO);
221 if (slot->stdout_fd == -1)
Lars Hjemli939d32f2008-04-28 11:32:42 +0200222 return errno;
Lars Hjemli318d1062006-12-11 12:10:12 +0100223
Lars Hjemli939d32f2008-04-28 11:32:42 +0200224 /* Redirect stdout to lockfile */
John Keepingb31e9982018-06-20 07:29:14 +0200225 if (dup2(slot->lock_fd, STDOUT_FILENO) == -1)
Lars Hjemli939d32f2008-04-28 11:32:42 +0200226 return errno;
Lars Hjemli318d1062006-12-11 12:10:12 +0100227
Lars Hjemli939d32f2008-04-28 11:32:42 +0200228 /* Generate cache content */
Lukas Fleischerf60ffa12014-01-15 21:53:15 +0100229 slot->fn();
Lars Hjemli318d1062006-12-11 12:10:12 +0100230
John Keeping3b485cc2017-04-24 19:38:34 +0100231 /* Make sure any buffered data is flushed to the file */
John Keepingb31e9982018-06-20 07:29:14 +0200232 if (fflush(stdout))
John Keeping3b485cc2017-04-24 19:38:34 +0100233 return errno;
John Keeping3b485cc2017-04-24 19:38:34 +0100234
Sebastian Andrzej Siewiord3581b52014-01-18 21:24:58 +0100235 /* update stat info */
John Keepingb31e9982018-06-20 07:29:14 +0200236 if (fstat(slot->lock_fd, &slot->cache_st))
Lars Hjemlid4028112008-05-18 23:16:50 +0200237 return errno;
238
Lars Hjemli939d32f2008-04-28 11:32:42 +0200239 return 0;
Lars Hjemli25105d72006-12-10 22:31:36 +0100240}
241
Lars Hjemli939d32f2008-04-28 11:32:42 +0200242/* Crude implementation of 32-bit FNV-1 hash algorithm,
243 * see http://www.isthe.com/chongo/tech/comp/fnv/ for details
244 * about the magic numbers.
245 */
246#define FNV_OFFSET 0x811c9dc5
247#define FNV_PRIME 0x01000193
248
249unsigned long hash_str(const char *str)
Lars Hjemli25105d72006-12-10 22:31:36 +0100250{
Lars Hjemli939d32f2008-04-28 11:32:42 +0200251 unsigned long h = FNV_OFFSET;
252 unsigned char *s = (unsigned char *)str;
253
254 if (!s)
255 return h;
256
Jason A. Donenfeldbdae1d82013-03-03 23:21:33 -0500257 while (*s) {
Lars Hjemli939d32f2008-04-28 11:32:42 +0200258 h *= FNV_PRIME;
259 h ^= *s++;
260 }
261 return h;
Lars Hjemli25105d72006-12-10 22:31:36 +0100262}
263
Lars Hjemli939d32f2008-04-28 11:32:42 +0200264static int process_slot(struct cache_slot *slot)
Lars Hjemlifbaf1172006-12-11 22:53:50 +0100265{
Lars Hjemli939d32f2008-04-28 11:32:42 +0200266 int err;
Lars Hjemlifbaf1172006-12-11 22:53:50 +0100267
Lars Hjemli939d32f2008-04-28 11:32:42 +0200268 err = open_slot(slot);
269 if (!err && slot->match) {
270 if (is_expired(slot)) {
271 if (!lock_slot(slot)) {
272 /* If the cachefile has been replaced between
273 * `open_slot` and `lock_slot`, we'll just
274 * serve the stale content from the original
275 * cachefile. This way we avoid pruning the
276 * newly generated slot. The same code-path
277 * is chosen if fill_slot() fails for some
278 * reason.
279 *
280 * TODO? check if the new slot contains the
281 * same key as the old one, since we would
282 * prefer to serve the newest content.
283 * This will require us to open yet another
284 * file-descriptor and read and compare the
285 * key from the new file, so for now we're
286 * lazy and just ignore the new file.
287 */
288 if (is_modified(slot) || fill_slot(slot)) {
289 unlock_slot(slot, 0);
290 close_lock(slot);
291 } else {
292 close_slot(slot);
293 unlock_slot(slot, 1);
294 slot->cache_fd = slot->lock_fd;
295 }
296 }
297 }
Lars Hjemliaf2e7562008-05-18 23:59:11 +0200298 if ((err = print_slot(slot)) != 0) {
299 cache_log("[cgit] error printing cache %s: %s (%d)\n",
300 slot->cache_name,
301 strerror(err),
302 err);
303 }
Lars Hjemli939d32f2008-04-28 11:32:42 +0200304 close_slot(slot);
Lars Hjemliaf2e7562008-05-18 23:59:11 +0200305 return err;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200306 }
307
308 /* If the cache slot does not exist (or its key doesn't match the
309 * current key), lets try to create a new cache slot for this
310 * request. If this fails (for whatever reason), lets just generate
Ville Skyttä67d0f872017-10-14 22:05:51 +0300311 * the content without caching it and fool the caller to believe
Lars Hjemli939d32f2008-04-28 11:32:42 +0200312 * everything worked out (but print a warning on stdout).
313 */
314
315 close_slot(slot);
316 if ((err = lock_slot(slot)) != 0) {
317 cache_log("[cgit] Unable to lock slot %s: %s (%d)\n",
318 slot->lock_name, strerror(err), err);
Lukas Fleischerf60ffa12014-01-15 21:53:15 +0100319 slot->fn();
Lars Hjemli939d32f2008-04-28 11:32:42 +0200320 return 0;
321 }
322
323 if ((err = fill_slot(slot)) != 0) {
324 cache_log("[cgit] Unable to fill slot %s: %s (%d)\n",
325 slot->lock_name, strerror(err), err);
326 unlock_slot(slot, 0);
327 close_lock(slot);
Lukas Fleischerf60ffa12014-01-15 21:53:15 +0100328 slot->fn();
Lars Hjemli939d32f2008-04-28 11:32:42 +0200329 return 0;
330 }
331 // We've got a valid cache slot in the lock file, which
332 // is about to replace the old cache slot. But if we
333 // release the lockfile and then try to open the new cache
334 // slot, we might get a race condition with a concurrent
335 // writer for the same cache slot (with a different key).
336 // Lets avoid such a race by just printing the content of
337 // the lock file.
338 slot->cache_fd = slot->lock_fd;
339 unlock_slot(slot, 1);
Lars Hjemliaf2e7562008-05-18 23:59:11 +0200340 if ((err = print_slot(slot)) != 0) {
341 cache_log("[cgit] error printing cache %s: %s (%d)\n",
342 slot->cache_name,
343 strerror(err),
344 err);
345 }
Lars Hjemli939d32f2008-04-28 11:32:42 +0200346 close_slot(slot);
347 return err;
Lars Hjemli25105d72006-12-10 22:31:36 +0100348}
Lars Hjemli939d32f2008-04-28 11:32:42 +0200349
350/* Print cached content to stdout, generate the content if necessary. */
351int cache_process(int size, const char *path, const char *key, int ttl,
Lukas Fleischerf60ffa12014-01-15 21:53:15 +0100352 cache_fill_fn fn)
Lars Hjemli939d32f2008-04-28 11:32:42 +0200353{
354 unsigned long hash;
John Keepingfb3655d2013-04-06 10:28:57 +0100355 int i;
356 struct strbuf filename = STRBUF_INIT;
357 struct strbuf lockname = STRBUF_INIT;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200358 struct cache_slot slot;
John Keepingf75900b2013-05-18 18:28:14 +0100359 int result;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200360
361 /* If the cache is disabled, just generate the content */
Lukas Fleischer6ceba452014-02-20 20:59:22 +0100362 if (size <= 0 || ttl == 0) {
Lukas Fleischerf60ffa12014-01-15 21:53:15 +0100363 fn();
Lars Hjemli939d32f2008-04-28 11:32:42 +0200364 return 0;
365 }
366
367 /* Verify input, calculate filenames */
368 if (!path) {
369 cache_log("[cgit] Cache path not specified, caching is disabled\n");
Lukas Fleischerf60ffa12014-01-15 21:53:15 +0100370 fn();
Lars Hjemli939d32f2008-04-28 11:32:42 +0200371 return 0;
372 }
Lars Hjemli939d32f2008-04-28 11:32:42 +0200373 if (!key)
374 key = "";
375 hash = hash_str(key) % size;
John Keepingfb3655d2013-04-06 10:28:57 +0100376 strbuf_addstr(&filename, path);
377 strbuf_ensure_end(&filename, '/');
Jason A. Donenfeldbdae1d82013-03-03 23:21:33 -0500378 for (i = 0; i < 8; i++) {
John Keepingfb3655d2013-04-06 10:28:57 +0100379 strbuf_addf(&filename, "%x", (unsigned char)(hash & 0xf));
Lars Hjemli939d32f2008-04-28 11:32:42 +0200380 hash >>= 4;
381 }
John Keepingfb3655d2013-04-06 10:28:57 +0100382 strbuf_addbuf(&lockname, &filename);
383 strbuf_addstr(&lockname, ".lock");
Lars Hjemli939d32f2008-04-28 11:32:42 +0200384 slot.fn = fn;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200385 slot.ttl = ttl;
John Keepingb31e9982018-06-20 07:29:14 +0200386 slot.stdout_fd = -1;
John Keepingf75900b2013-05-18 18:28:14 +0100387 slot.cache_name = filename.buf;
388 slot.lock_name = lockname.buf;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200389 slot.key = key;
390 slot.keylen = strlen(key);
John Keepingf75900b2013-05-18 18:28:14 +0100391 result = process_slot(&slot);
392
393 strbuf_release(&filename);
394 strbuf_release(&lockname);
395 return result;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200396}
397
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200398/* Return a strftime formatted date/time
399 * NB: the result from this function is to shared memory
400 */
Lukas Fleischerbafab422013-03-04 08:52:33 +0100401static char *sprintftime(const char *format, time_t time)
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200402{
403 static char buf[64];
404 struct tm *tm;
405
406 if (!time)
407 return NULL;
408 tm = gmtime(&time);
409 strftime(buf, sizeof(buf)-1, format, tm);
410 return buf;
411}
412
413int cache_ls(const char *path)
414{
415 DIR *dir;
416 struct dirent *ent;
417 int err = 0;
John Keeping80d52072015-03-08 16:32:26 +0000418 struct cache_slot slot = { NULL };
John Keepingfb3655d2013-04-06 10:28:57 +0100419 struct strbuf fullname = STRBUF_INIT;
420 size_t prefixlen;
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200421
422 if (!path) {
423 cache_log("[cgit] cache path not specified\n");
424 return -1;
425 }
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200426 dir = opendir(path);
427 if (!dir) {
428 err = errno;
429 cache_log("[cgit] unable to open path %s: %s (%d)\n",
430 path, strerror(err), err);
431 return err;
432 }
John Keepingfb3655d2013-04-06 10:28:57 +0100433 strbuf_addstr(&fullname, path);
434 strbuf_ensure_end(&fullname, '/');
435 prefixlen = fullname.len;
Jason A. Donenfeldbdae1d82013-03-03 23:21:33 -0500436 while ((ent = readdir(dir)) != NULL) {
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200437 if (strlen(ent->d_name) != 8)
438 continue;
John Keepingfb3655d2013-04-06 10:28:57 +0100439 strbuf_setlen(&fullname, prefixlen);
440 strbuf_addstr(&fullname, ent->d_name);
John Keepingf75900b2013-05-18 18:28:14 +0100441 slot.cache_name = fullname.buf;
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200442 if ((err = open_slot(&slot)) != 0) {
443 cache_log("[cgit] unable to open path %s: %s (%d)\n",
John Keepingfb3655d2013-04-06 10:28:57 +0100444 fullname.buf, strerror(err), err);
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200445 continue;
446 }
John Keepingf32a2da2013-05-18 18:46:39 +0100447 htmlf("%s %s %10"PRIuMAX" %s\n",
448 fullname.buf,
449 sprintftime("%Y-%m-%d %H:%M:%S",
450 slot.cache_st.st_mtime),
451 (uintmax_t)slot.cache_st.st_size,
452 slot.buf);
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200453 close_slot(&slot);
454 }
455 closedir(dir);
John Keepingf75900b2013-05-18 18:28:14 +0100456 strbuf_release(&fullname);
Lars Hjemli9000bbf2008-04-28 12:10:13 +0200457 return 0;
458}
459
Lars Hjemli939d32f2008-04-28 11:32:42 +0200460/* Print a message to stdout */
461void cache_log(const char *format, ...)
462{
463 va_list args;
464 va_start(args, format);
465 vfprintf(stderr, format, args);
466 va_end(args);
467}
468