RFD: return code for mogtool listkey

Robin H. Johnson robbat2 at gentoo.org
Thu Jun 21 13:45:59 UTC 2007


Hi folks,

I didn't want to commit this change blindly, since somebody might be depending
on the behavior.

When you use 'mogtool listkey', I want exit with a non-zero code if no files
were found. This saves having to parse the output.

Opinions?

==============

Give an non-zero return code if listkey returns no output.
    
Signed-off-by: Robin H. Johnson <robbat2 at gentoo.org>

diff --git a/utils/mogtool b/utils/mogtool
index 2a0b17a..7d822ea 100755
--- a/utils/mogtool
+++ b/utils/mogtool
@@ -1249,6 +1249,7 @@ sub listkey {
 
     # list all files matchine a key
     my ($ct, $after, $list);
+    $ct = 0;
     while (($after, $list) = $mogfs->list_keys("$key_pattern", $after)) {
         last unless $list && @$list;
 
@@ -1261,7 +1262,8 @@ sub listkey {
         }
     }
     print "#$ct files found\n";
-    exit 0;
+    exit 0 if($ct gt 0);
+    exit 1;
 }
 
 sub mdelete {

-- 
Robin Hugh Johnson
Gentoo Linux Developer & Council Member
E-Mail     : robbat2 at gentoo.org
GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 321 bytes
Desc: not available
Url : http://lists.danga.com/pipermail/mogilefs/attachments/20070621/47a67ca1/attachment.pgp


More information about the mogilefs mailing list