[Pkg-privacy-commits] [libgsecuredelete] 02/25: Report warning message on partial success

Intrigeri intrigeri at moszumanska.debian.org
Wed Dec 7 17:10:33 UTC 2016


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to branch master
in repository libgsecuredelete.

commit bdb0b19d17aaf0858fa9e2358847f9f1fe7b8f46
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Tue Jul 12 20:10:43 2016 +0200

    Report warning message on partial success
    
    Report warning messages to the Gsd.AsyncOperation.finished signal when
    the sub-process succeeded with warnings.  This allows `sfill` to report
    a warning message when it failed to gain root access without reporting
    overall failure.
---
 gsecuredelete/gsd-async-operation.vala | 31 +++++++++++++++++++++++++++----
 gsecuredelete/gsd-fill-operation.vala  | 10 ++++++++++
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/gsecuredelete/gsd-async-operation.vala b/gsecuredelete/gsd-async-operation.vala
index 1a3bfbe..2699702 100644
--- a/gsecuredelete/gsd-async-operation.vala
+++ b/gsecuredelete/gsd-async-operation.vala
@@ -94,6 +94,16 @@ namespace Gsd
    */
   public abstract class AsyncOperation : Object
   {
+    /* possible subprocess exit status classification */
+    protected enum ExitStatus {
+      /* full success */
+      SUCCESS,
+      /* success, but warnings issued (possibly non-fatal error) */
+      WARNING,
+      /* error (fatal failures) */
+      ERROR
+    }
+    
     /* fields for async operation */
     /**
      * The maximum number of progress steps.
@@ -128,7 +138,7 @@ namespace Gsd
      * This signal is emitted when the operation just terminated.
      * 
      * @param success whether the operation succeed.
-     * @param message if the operation failed, contains the error message.
+     * @param message any error or warning message.
      */
     public signal void finished (bool     success,
                                  string?  message);
@@ -266,6 +276,12 @@ namespace Gsd
       }
     }
     
+    /* Classifies the subprocess exit status */
+    protected virtual ExitStatus classify_exit_status (int exit_status)
+    {
+      return exit_status == 0 ? ExitStatus.SUCCESS : ExitStatus.ERROR;
+    }
+    
     /* checks if the child finished, and dispatches related things.
      * 
      * It is meant to be called as a timeout function.
@@ -293,10 +309,17 @@ namespace Gsd
       } else {
         if (! Process.if_exited (exit_status)) {
           message = "Subprocess crashed.\n" + get_subprocess_error_msg ();
-        } else if (Process.exit_status (exit_status) != 0) {
-          message = "Subprocess failed.\n" + get_subprocess_error_msg ();
         } else {
-          success = true;
+          int         status_int  = Process.exit_status (exit_status);
+          ExitStatus  status      = this.classify_exit_status (status_int);
+          
+          if (status == ExitStatus.WARNING) {
+            message = get_subprocess_error_msg ();
+          } else if (status == ExitStatus.ERROR) {
+            message = "Subprocess failed.\n" + get_subprocess_error_msg ();
+          }
+          
+          success = (status != ExitStatus.ERROR);
         }
       }
       
diff --git a/gsecuredelete/gsd-fill-operation.vala b/gsecuredelete/gsd-fill-operation.vala
index 21be0cf..dc5eebc 100644
--- a/gsecuredelete/gsd-fill-operation.vala
+++ b/gsecuredelete/gsd-fill-operation.vala
@@ -110,6 +110,16 @@ namespace Gsd
       this.directory = null;
     }
     
+    protected override AsyncOperation.ExitStatus classify_exit_status (int exit_status)
+    {
+      switch (exit_status) {
+        case 0:   return ExitStatus.SUCCESS;
+        /* gsd-sfill-helper special case */
+        case 42:  return ExitStatus.WARNING;
+        default:  return ExitStatus.ERROR;
+      }
+    }
+    
     /**
      * Launches a secure filling asynchronously.
      * 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libgsecuredelete.git



More information about the Pkg-privacy-commits mailing list