grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v4 3/6] commands/ls: Show modification time for file paths


From: Glenn Washburn
Subject: [PATCH v4 3/6] commands/ls: Show modification time for file paths
Date: Mon, 6 Jan 2025 01:02:41 -0600

The modification time for paths to files was not being printed because
the grub_dirhook_info, which contains the mtime, was initialized to NULL.
Instead of calling print_file() directly, use fs->fs_dir() to call
print_file() with a properly filled in grub_dirhook_info. This has the
added benefit of reducing code complexity.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/commands/ls.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c
index 43ee6aca085a..ed296a536554 100644
--- a/grub-core/commands/ls.c
+++ b/grub-core/commands/ls.c
@@ -87,6 +87,7 @@ grub_ls_list_devices (int longlist)
 struct grub_ls_list_files_ctx
 {
   char *dirname;
+  char *filename;
   int all;
   int human;
   int longlist;
@@ -102,6 +103,9 @@ print_file (const char *filename, const struct 
grub_dirhook_info *info,
   if ((! ctx->all) && (filename[0] == '.'))
     return 0;
 
+  if ((ctx->filename != NULL) && (grub_strcmp (filename, ctx->filename) != 0))
+    return 0;
+
   if (! ctx->longlist)
     {
       grub_printf ("%s%s ", filename, info->dir ? "/" : "");
@@ -210,6 +214,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, 
int human)
     {
       struct grub_ls_list_files_ctx ctx = {
        .dirname = dirname,
+       .filename = NULL,
        .all = all,
        .human = human,
        .longlist = longlist
@@ -220,26 +225,19 @@ grub_ls_list_files (char *dirname, int longlist, int all, 
int human)
       if (grub_errno == GRUB_ERR_BAD_FILE_TYPE
          && path[grub_strlen (path) - 1] != '/')
        {
-         /* PATH might be a regular file.  */
-         char *p;
-         grub_file_t file;
-         struct grub_dirhook_info info;
-         grub_errno = 0;
-
-         file = grub_file_open (dirname, GRUB_FILE_TYPE_GET_SIZE
-                                | GRUB_FILE_TYPE_NO_DECOMPRESS);
-         if (! file)
-           goto fail;
+         /*
+          * Reset errno as it is currently set, but will cause subsequent code
+          * to think there is an error.
+          */
+         grub_errno = GRUB_ERR_NONE;
 
-         grub_file_close (file);
-
-         p = grub_strrchr (dirname, '/') + 1;
-         ctx.dirname = grub_strndup (dirname, p - dirname);
+         /* PATH might be a regular file.  */
+         ctx.filename = grub_strrchr (dirname, '/') + 1;
+         ctx.dirname = grub_strndup (dirname, ctx.filename - dirname);
          if (ctx.dirname == NULL)
            goto fail;
 
-         grub_memset (&info, 0, sizeof (info));
-         print_file (p, &info, &ctx);
+         (fs->fs_dir) (dev, ctx.dirname + (path - dirname), print_file, &ctx);
 
          grub_free (ctx.dirname);
        }
-- 
2.34.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]