cgit

commit f32a2da636ffa6eaa6b8d0d3f35a673fa12e404a

Author: John Keeping <john@keeping.me.uk>

cache.c: cache ls_cache output properly

By using the standard library's printf, cache_ls does not redirect its
output to the cache when we change the process' stdout file descriptor
to point to the cache file.  Fix this by using "htmlf" in the same way
that we do for writing HTTP headers.

Signed-off-by: John Keeping <john@keeping.me.uk>

 cache.c | 13 +++++++------
 tests/t0020-validate-cache.sh | 8 +++++++-


diff --git a/cache.c b/cache.c
index 74a1795a884051d480806323023209b88aa33b5c..aa870e3654125cf6017d5f7d6d0f21da8a549a0e 100644
--- a/cache.c
+++ b/cache.c
@@ -15,6 +15,7 @@  */
 
 #include "cgit.h"
 #include "cache.h"
+#include "html.h"
 
 #define CACHE_BUFSIZE (1024 * 4)
 
@@ -404,12 +405,12 @@ 			cache_log("[cgit] unable to open path %s: %s (%d)\n",
 				  fullname.buf, strerror(err), err);
 			continue;
 		}
-		printf("%s %s %10"PRIuMAX" %s\n",
-		       fullname.buf,
-		       sprintftime("%Y-%m-%d %H:%M:%S",
-				   slot.cache_st.st_mtime),
-		       (uintmax_t)slot.cache_st.st_size,
-		       slot.buf);
+		htmlf("%s %s %10"PRIuMAX" %s\n",
+		      fullname.buf,
+		      sprintftime("%Y-%m-%d %H:%M:%S",
+				  slot.cache_st.st_mtime),
+		      (uintmax_t)slot.cache_st.st_size,
+		      slot.buf);
 		close_slot(&slot);
 	}
 	closedir(dir);




diff --git a/tests/t0020-validate-cache.sh b/tests/t0020-validate-cache.sh
index 7e7379a80a898651484b4f395c5e4c3cc21c40e9..657765d897b5da5dc7f13231c8e0fd2467086a05 100755
--- a/tests/t0020-validate-cache.sh
+++ b/tests/t0020-validate-cache.sh
@@ -66,7 +66,13 @@ 	cgit_url "bar/log" &&
 	cgit_url "bar/diff" &&
 	cgit_url "bar/patch" &&
 	ls cache >output &&
-	test_line_count = 13 output
+	test_line_count = 13 output &&
+	cgit_url "foo/ls_cache" >output.full &&
+	strip_headers <output.full >output &&
+	test_line_count = 13 output &&
+	# Check that ls_cache output is cached correctly
+	cgit_url "foo/ls_cache" >output.second &&
+	test_cmp output.full output.second
 '
 
 test_done