* [PATCH] cmp: Only return success when both files have the same contents
@ 2022-08-26 0:56 Glenn Washburn
2022-09-29 14:00 ` Daniel Kiper
0 siblings, 1 reply; 4+ messages in thread
From: Glenn Washburn @ 2022-08-26 0:56 UTC (permalink / raw)
To: grub-devel, Daniel Kiper; +Cc: Li Gen, Glenn Washburn
From: Li Gen <ligenlive@gmail.com>
This allows the cmp command to be used in GRUB scripts to conditionally
run commands based on whether two files are the same.
Signed-off-by: Li Gen <ligenlive@gmail.com>
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/commands/cmp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c
index e9c3b25d34..e1665cf27b 100644
--- a/grub-core/commands/cmp.c
+++ b/grub-core/commands/cmp.c
@@ -38,6 +38,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
grub_file_t file2 = 0;
char *buf1 = 0;
char *buf2 = 0;
+ grub_err_t err = GRUB_ERR_TEST_FAILURE;
if (argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
@@ -91,6 +92,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
/* TRANSLATORS: it's always exactly 2 files. */
grub_printf_ (N_("The files are identical.\n"));
+ err = GRUB_ERR_NONE;
}
cleanup:
@@ -102,7 +104,7 @@ cleanup:
if (file2)
grub_file_close (file2);
- return grub_errno;
+ return err;
}
static grub_command_t cmd;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] cmp: Only return success when both files have the same contents
2022-08-26 0:56 [PATCH] cmp: Only return success when both files have the same contents Glenn Washburn
@ 2022-09-29 14:00 ` Daniel Kiper
2022-10-01 5:44 ` Glenn Washburn
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Kiper @ 2022-09-29 14:00 UTC (permalink / raw)
To: Glenn Washburn; +Cc: grub-devel, Li Gen
On Thu, Aug 25, 2022 at 07:56:29PM -0500, Glenn Washburn wrote:
> From: Li Gen <ligenlive@gmail.com>
>
> This allows the cmp command to be used in GRUB scripts to conditionally
> run commands based on whether two files are the same.
>
> Signed-off-by: Li Gen <ligenlive@gmail.com>
> Signed-off-by: Glenn Washburn <development@efficientek.com>
> ---
> grub-core/commands/cmp.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c
> index e9c3b25d34..e1665cf27b 100644
> --- a/grub-core/commands/cmp.c
> +++ b/grub-core/commands/cmp.c
> @@ -38,6 +38,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
> grub_file_t file2 = 0;
> char *buf1 = 0;
> char *buf2 = 0;
> + grub_err_t err = GRUB_ERR_TEST_FAILURE;
>
> if (argc != 2)
> return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
> @@ -91,6 +92,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
>
> /* TRANSLATORS: it's always exactly 2 files. */
> grub_printf_ (N_("The files are identical.\n"));
I think we should add a quite option to not switch video mode if it is
not needed. And these new cmp features should be mentioned in doc.
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cmp: Only return success when both files have the same contents
2022-09-29 14:00 ` Daniel Kiper
@ 2022-10-01 5:44 ` Glenn Washburn
2022-10-03 14:56 ` Daniel Kiper
0 siblings, 1 reply; 4+ messages in thread
From: Glenn Washburn @ 2022-10-01 5:44 UTC (permalink / raw)
To: Daniel Kiper; +Cc: grub-devel, Li Gen
On Thu, 29 Sep 2022 16:00:59 +0200
Daniel Kiper <dkiper@net-space.pl> wrote:
> On Thu, Aug 25, 2022 at 07:56:29PM -0500, Glenn Washburn wrote:
> > From: Li Gen <ligenlive@gmail.com>
> >
> > This allows the cmp command to be used in GRUB scripts to conditionally
> > run commands based on whether two files are the same.
> >
> > Signed-off-by: Li Gen <ligenlive@gmail.com>
> > Signed-off-by: Glenn Washburn <development@efficientek.com>
> > ---
> > grub-core/commands/cmp.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c
> > index e9c3b25d34..e1665cf27b 100644
> > --- a/grub-core/commands/cmp.c
> > +++ b/grub-core/commands/cmp.c
> > @@ -38,6 +38,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
> > grub_file_t file2 = 0;
> > char *buf1 = 0;
> > char *buf2 = 0;
> > + grub_err_t err = GRUB_ERR_TEST_FAILURE;
> >
> > if (argc != 2)
> > return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
> > @@ -91,6 +92,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
> >
> > /* TRANSLATORS: it's always exactly 2 files. */
> > grub_printf_ (N_("The files are identical.\n"));
>
> I think we should add a quite option to not switch video mode if it is
> not needed. And these new cmp features should be mentioned in doc.
To adding a quiet mode, I completely agree and thought about adding it.
I decided against it in this patch because it didn't seem related. I
might get around to doing it, but it could be a while. What do you
think about having instead a verbose mode, and the default being quiet?
Since doing some logic based on cmp output should not really be
happening, I don't think this should be a problem, only might cause
some people not to see expected output.
As for a documentation update, agreed. I try to find some time this
week to submit a v2 adding the documentation.
Glenn
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cmp: Only return success when both files have the same contents
2022-10-01 5:44 ` Glenn Washburn
@ 2022-10-03 14:56 ` Daniel Kiper
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2022-10-03 14:56 UTC (permalink / raw)
To: Glenn Washburn; +Cc: grub-devel, Li Gen
On Sat, Oct 01, 2022 at 12:44:50AM -0500, Glenn Washburn wrote:
> On Thu, 29 Sep 2022 16:00:59 +0200
> Daniel Kiper <dkiper@net-space.pl> wrote:
>
> > On Thu, Aug 25, 2022 at 07:56:29PM -0500, Glenn Washburn wrote:
> > > From: Li Gen <ligenlive@gmail.com>
> > >
> > > This allows the cmp command to be used in GRUB scripts to conditionally
> > > run commands based on whether two files are the same.
> > >
> > > Signed-off-by: Li Gen <ligenlive@gmail.com>
> > > Signed-off-by: Glenn Washburn <development@efficientek.com>
> > > ---
> > > grub-core/commands/cmp.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c
> > > index e9c3b25d34..e1665cf27b 100644
> > > --- a/grub-core/commands/cmp.c
> > > +++ b/grub-core/commands/cmp.c
> > > @@ -38,6 +38,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
> > > grub_file_t file2 = 0;
> > > char *buf1 = 0;
> > > char *buf2 = 0;
> > > + grub_err_t err = GRUB_ERR_TEST_FAILURE;
> > >
> > > if (argc != 2)
> > > return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
> > > @@ -91,6 +92,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
> > >
> > > /* TRANSLATORS: it's always exactly 2 files. */
> > > grub_printf_ (N_("The files are identical.\n"));
> >
> > I think we should add a quite option to not switch video mode if it is
> > not needed. And these new cmp features should be mentioned in doc.
>
> To adding a quiet mode, I completely agree and thought about adding it.
> I decided against it in this patch because it didn't seem related. I
> might get around to doing it, but it could be a while. What do you
> think about having instead a verbose mode, and the default being quiet?
Yeah, I thought about it too. Go for it!.
> Since doing some logic based on cmp output should not really be
> happening, I don't think this should be a problem, only might cause
> some people not to see expected output.
Yep, but I do not expect many users of cmp command right now...
> As for a documentation update, agreed. I try to find some time this
> week to submit a v2 adding the documentation.
Cool! Thanks!
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-03 14:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26 0:56 [PATCH] cmp: Only return success when both files have the same contents Glenn Washburn
2022-09-29 14:00 ` Daniel Kiper
2022-10-01 5:44 ` Glenn Washburn
2022-10-03 14:56 ` Daniel Kiper
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.