ls: When -h is passed, the total should also be in human units
authorLauri Kasanen <cand@gmx.com>
Wed, 1 Aug 2018 16:51:17 +0000 (19:51 +0300)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 1 Aug 2018 17:47:15 +0000 (19:47 +0200)
Signed-off-by: Lauri Kasanen <cand@gmx.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
coreutils/ls.c

index 4be499088062b88d94f9c2163353d5865ebfa5c4..b1c306809af7c033facad0f198e24bd63ae0aabc 100644 (file)
@@ -1016,7 +1016,15 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
                subdnp = scan_one_dir((*dn)->fullname, &nfiles);
 #if ENABLE_DESKTOP
                if (option_mask32 & (OPT_s|OPT_l)) {
-                       printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
+                       if (option_mask32 & OPT_h) {
+                               printf("total %-"HUMAN_READABLE_MAX_WIDTH_STR"s\n",
+                                       /* print size, no fractions, use suffixes */
+                                       make_human_readable_str(calculate_blocks(subdnp) * 1024,
+                                                               0, 0)
+                               );
+                       } else {
+                               printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
+                       }
                }
 #endif
                if (nfiles > 0) {