Module Name:    src
Committed By:   mrg
Date:           Wed Nov 21 10:25:17 UTC 2018

Modified Files:
        src/libexec/httpd: dir-index-bozo.c

Log Message:
two fixes reported by mouse:
- don't check contents of 'st' if stat(2) failed.
- round up instead of truncate.  now 10000 byte files say 10kB not 9kB.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/libexec/httpd/dir-index-bozo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/dir-index-bozo.c
diff -u src/libexec/httpd/dir-index-bozo.c:1.26 src/libexec/httpd/dir-index-bozo.c:1.27
--- src/libexec/httpd/dir-index-bozo.c:1.26	Tue Nov 20 01:06:46 2018
+++ src/libexec/httpd/dir-index-bozo.c	Wed Nov 21 10:25:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir-index-bozo.c,v 1.26 2018/11/20 01:06:46 mrg Exp $	*/
+/*	$NetBSD: dir-index-bozo.c,v 1.27 2018/11/21 10:25:17 mrg Exp $	*/
 
 /*	$eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $	*/
 
@@ -157,7 +157,7 @@ bozo_dir_index(bozo_httpreq_t *request, 
 		if (strcmp(name, "..") == 0) {
 			bozo_printf(httpd, "<a href=\"../\">");
 			l += bozo_printf(httpd, "Parent Directory");
-		} else if (S_ISDIR(sb.st_mode)) {
+		} else if (!nostat && S_ISDIR(sb.st_mode)) {
 			bozo_printf(httpd, "<a href=\"%s/\">", urlname);
 			l += bozo_printf(httpd, "%s/", htmlname);
 		} else if (strchr(name, ':') != NULL) {
@@ -185,6 +185,10 @@ bozo_dir_index(bozo_httpreq_t *request, 
 		if (nostat)
 			bozo_printf(httpd, "?                         ?");
 		else {
+			unsigned long long len;
+
+			len = ((unsigned long long)sb.st_size + 1023) / 1024;
+
 			tm = gmtime(&sb.st_mtime);
 			strftime(buf, sizeof buf, "%d-%b-%Y %R", tm);
 			l += bozo_printf(httpd, "%s", buf);
@@ -199,8 +203,7 @@ bozo_dir_index(bozo_httpreq_t *request, 
 			spacebuf[i] = '\0';
 			bozo_printf(httpd, "%s", spacebuf);
 
-			bozo_printf(httpd, "%12llukB",
-				    (unsigned long long)sb.st_size >> 10);
+			bozo_printf(httpd, "%12llukB", len);
 		}
 		bozo_printf(httpd, "\r\n");
 	}

Reply via email to