Skip to contentSkip to conversation

commands/ls: Print ???????????? if unable to get file size

PATCH In review Glenn Washburn 2 participants 2 messages Aug 14, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 commands/ls: Print ???????????? if unable to get file size

In long list mode, if the file can not be opened, the file is not printed. Instead, print the file but print the size as ????????????.

---
 grub-core/commands/ls.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
grub-core/commands/ls.c +10 -10
index c746eae0c7e7..6a1c7f5d3626 100644
@@ -131,20 +131,20 @@ print_files_long (const char *filename, const struct grub_dirhook_info *info,
 	 should be reported as directories.  */
       file = grub_file_open (pathname, GRUB_FILE_TYPE_GET_SIZE
 			     | GRUB_FILE_TYPE_NO_DECOMPRESS);
-      if (! file)
+      if (file)
 	{
-	  grub_errno = 0;
-	  grub_free (pathname);
-	  return 0;
+	  if (! ctx->human)
+	    grub_printf ("%-12llu", (unsigned long long) file->size);
+	  else
+	    grub_printf ("%-12s", grub_get_human_size (file->size,
+						   GRUB_HUMAN_SIZE_SHORT));
+	  grub_file_close (file);
 	}
-
-      if (! ctx->human)
-	grub_printf ("%-12llu", (unsigned long long) file->size);
       else
-	grub_printf ("%-12s", grub_get_human_size (file->size,
-						   GRUB_HUMAN_SIZE_SHORT));
-      grub_file_close (file);
+	grub_xputs ("????????????");
+
       grub_free (pathname);
+      grub_errno = GRUB_ERR_NONE;
     }
   else
     grub_printf ("%-12s", _("DIR"));
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel