coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] df: fix exit code and ensure printing "unprocessed" msg when


From: Jim Meyering
Subject: Re: [PATCH] df: fix exit code and ensure printing "unprocessed" msg when totaling
Date: Sat, 04 Aug 2012 13:25:12 +0200

Pádraig Brady wrote:
> On 08/04/2012 12:11 AM, Bernhard Voelker wrote:
...
>> Subject: [PATCH] df: fix exit code and ensure printing "unprocessed" msg when
>>  totaling
>>
>> When the combination of the file system options with given files or
>> devices does not lead to output, "df --total" would exit successfully
>> although it should not.
>>
>> Examples:
>>   $ df --total --type=xfs /          # when / is not an XFS file system
>>   $ df --total --local -t nfs  DIR   # nfs is remote per se ...
>>   $ df --total -t qwerty /dev/sdb5   # typo in file system type
>>
>> Furthermore, "df --total" would not print the error message "no file
>> systems processed" when the file argument does not exist or is otherwise
>> not accessible.
>>
>> Example:
>>   $ df --total __not_exist__
>>
>> These 2 bugs are present since --total was added by commit
>> v6.12-166-gea2887b.
>
> Great stuff,
> thanks for all the detail and the test.

Seconded!

> I was half wondering if it should exit(SUCCESS) if
> anything was processed, but I think your patch is best as is,
> at least for consistency with df without --total, and du --total.

I agree.

> I'll apply in a little while, after I review fully.

Here are a couple of potential changes to consider:

When there has already been a diagnostic (e.g., "no such file"),
I prefer not to print the "no file systems processed" diagnostic
since the presence of the latter may make someone miss the former
("real") error.

Also, with --total, there's no point in printing totals
when we've done nothing and are about to fail with the
"no file systems processed" diagnostic.

Of course, with these changes, the new tests would have
to be adjusted, and maybe extended.

diff --git a/src/df.c b/src/df.c
index f7e481e..b796568 100644
--- a/src/df.c
+++ b/src/df.c
@@ -1125,7 +1125,8 @@ main (int argc, char **argv)
   else
     get_all_entries ();

-  if (print_grand_total)
+  /* With --total, don't print totals if we've processed no FS.  */
+  if (print_grand_total && file_systems_processed)
     {
       if (inode_format)
         grand_fsu.fsu_blocks = 1;
@@ -1134,7 +1135,9 @@ main (int argc, char **argv)

   print_table ();

-  if (! file_systems_processed)
+  /* Print the "no FS processed" diagnostic only if there was no preceding
+     diagnostic, e.g., if all have been excluded.  */
+  if (exit_status == 0 && ! file_systems_processed)
     error (EXIT_FAILURE, 0, _("no file systems processed"));

   exit (exit_status);
--
1.7.12.rc1.10.g97c7934



reply via email to

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