Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Format the cache listing's times where it prints
Diffstat (limited to 'source')
| -rw-r--r-- | source/cache.c | 23 |
1 file changed, 6 insertions, 17 deletions
diff --git a/source/cache.c b/source/cache.c index 5bedb87..efe8185 100644 --- a/source/cache.c +++ b/source/cache.c @@ -458,21 +458,6 @@ static int process_slot(struct cache_slot *slot) } /* - * The result lives in a static buffer and is only good until the next call. - */ -static const char *format_time(const char *format, time_t when) -{ - static char buf[64]; - struct tm tm; - - if (!when) - return "-"; - gmtime_r(&when, &tm); - strftime(buf, sizeof(buf) - 1, format, &tm); - return buf; -} - -/* * The accumulator is unsigned long, so on a 64 bit host this is not the * published FNV-1 value. Only slot selection depends on it. */ @@ -557,6 +542,9 @@ int cache_ls(const char *path) strbuf_ensure_end(&slot_path, '/'); prefixlen = slot_path.len; while ((ent = readdir(dir))) { + char mtime[64] = "-"; + struct tm tm; + if (strlen(ent->d_name) != SLOT_NAME_LEN) continue; strbuf_setlen(&slot_path, prefixlen); @@ -567,13 +555,14 @@ int cache_ls(const char *path) close_fd(&slot.cache_fd); continue; } + if (slot.st.st_mtime && gmtime_r(&slot.st.st_mtime, &tm)) + strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", &tm); // A truncated or corrupt slot may hold no NUL, so the print is // bounded by what was read and cannot run off the end. nul = memchr(slot.buf, 0, slot.buflen); keylen = nul ? (int)(nul - slot.buf) : slot.buflen; htmlf( - "%s %s %10"PRIuMAX" %.*s\n", slot_path.buf, - format_time("%Y-%m-%d %H:%M:%S", slot.st.st_mtime), + "%s %s %10"PRIuMAX" %.*s\n", slot_path.buf, mtime, (uintmax_t)slot.st.st_size, keylen, slot.buf ); close_fd(&slot.cache_fd); |
