cmp: Only return success when both files have the same contents
PATCH 1/1 cmp: Only return success when both files have the same contents
From: Li Gen <[email protected]>
This allows the cmp command to be used in GRUB scripts to conditionally run commands based on whether two files are the same.
--- grub-core/commands/cmp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
grub-core/commands/cmp.c +3 -1
@@ -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;
Signature · 1 line
2.34.1
Quoted 24 lines · Glenn Washburn
From: Li Gen <[email protected]>
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 <[email protected]>Signed-off-by Glenn Washburn <[email protected]>--- grub-core/commands/cmp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)grub-core/commands/cmp.c +1
-0@@ -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" ));
grub-core/commands/cmp.c grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), · line 94
Quoted 3 lines
grub-core/commands/cmp.c +0
-0@@ -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
Quoted 26 lines · On Thu, 29 Sep 2022 16:00:59 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 25 lines · Glenn Washburn
From: Li Gen <[email protected]>
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 <[email protected]>Signed-off-by Glenn Washburn <[email protected]>--- grub-core/commands/cmp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)grub-core/commands/cmp.c +1
-0@@ -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)),
Quoted 5 lines
grub-core/commands/cmp.c grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), · line 94
Quoted 2 lines
grub-core/commands/cmp.c +0
-0/* 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
Quoted 35 lines · Glenn Washburn
Quoted 26 lines · On Thu, 29 Sep 2022 16:00:59 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 25 lines · Glenn Washburn
From: Li Gen <[email protected]>
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 <[email protected]>Signed-off-by Glenn Washburn <[email protected]>--- grub-core/commands/cmp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)grub-core/commands/cmp.c +1
-0@@ -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)),Quoted 5 lines
grub-core/commands/cmp.c grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), · line 94
Quoted 2 lines
grub-core/commands/cmp.c +0
-0/* 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.
Quoted 4 lines
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!.
Quoted 3 lines
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...
Quoted 2 lines
As for a documentation update, agreed. I try to find some time this week to submit a v2 adding the documentation.
Cool! Thanks!
Daniel