commands/ls: Print full paths for file args
For arguments that are paths to files, print the full path of the file. Signed-off-by: Glenn Washburn <development@efficientek.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
90288fc48d
commit
096bf59e4c
@ -98,6 +98,7 @@ static int
|
|||||||
print_file (const char *filename, const struct grub_dirhook_info *info,
|
print_file (const char *filename, const struct grub_dirhook_info *info,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
|
char *pathname = NULL;
|
||||||
struct grub_ls_list_files_ctx *ctx = data;
|
struct grub_ls_list_files_ctx *ctx = data;
|
||||||
|
|
||||||
if ((! ctx->all) && (filename[0] == '.'))
|
if ((! ctx->all) && (filename[0] == '.'))
|
||||||
@ -117,7 +118,6 @@ print_file (const char *filename, const struct grub_dirhook_info *info,
|
|||||||
if (! info->dir)
|
if (! info->dir)
|
||||||
{
|
{
|
||||||
grub_file_t file;
|
grub_file_t file;
|
||||||
char *pathname;
|
|
||||||
|
|
||||||
if (ctx->dirname[grub_strlen (ctx->dirname) - 1] == '/')
|
if (ctx->dirname[grub_strlen (ctx->dirname) - 1] == '/')
|
||||||
pathname = grub_xasprintf ("%s%s", ctx->dirname, filename);
|
pathname = grub_xasprintf ("%s%s", ctx->dirname, filename);
|
||||||
@ -143,7 +143,6 @@ print_file (const char *filename, const struct grub_dirhook_info *info,
|
|||||||
else
|
else
|
||||||
grub_xputs ("????????????");
|
grub_xputs ("????????????");
|
||||||
|
|
||||||
grub_free (pathname);
|
|
||||||
grub_errno = GRUB_ERR_NONE;
|
grub_errno = GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -165,7 +164,16 @@ print_file (const char *filename, const struct grub_dirhook_info *info,
|
|||||||
datetime.day, datetime.hour,
|
datetime.day, datetime.hour,
|
||||||
datetime.minute, datetime.second);
|
datetime.minute, datetime.second);
|
||||||
}
|
}
|
||||||
grub_printf ("%s%s\n", filename, info->dir ? "/" : "");
|
/*
|
||||||
|
* Only print the full path when listing a file path given as an argument
|
||||||
|
* to ls, i.e. when ctx->filename != NULL. File listings that are printed
|
||||||
|
* due to showing the contents of a directory do not need a full path because
|
||||||
|
* the full path to the directory will have already been printed.
|
||||||
|
*/
|
||||||
|
grub_printf ("%s%s\n", (ctx->filename != NULL) ? pathname : filename,
|
||||||
|
info->dir ? "/" : "");
|
||||||
|
|
||||||
|
grub_free (pathname);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user