[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [k3b] /: Print real group of external binary with permission error.
From:       Johannes Obermayr <johannesobermayr () gmx ! de>
Date:       2014-10-05 16:50:08
Message-ID: E1Xap0a-0003f4-NK () scm ! kde ! org
[Download RAW message or body]

Git commit 83943c1bbe314392434246d620f0bc69679f6070 by Johannes Obermayr.
Committed on 04/10/2014 at 15:13.
Pushed by jobermayr into branch 'master'.

Print real group of external binary with permission error.

This commit enhances commit 7bb5979.

M  +23   -13   libk3b/core/k3bexternalbinmanager.cpp
M  +3    -3    libk3b/core/k3bexternalbinmanager.h
M  +7    -7    src/k3bsystemproblemdialog.cpp

http://commits.kde.org/k3b/83943c1bbe314392434246d620f0bc69679f6070

diff --git a/libk3b/core/k3bexternalbinmanager.cpp \
b/libk3b/core/k3bexternalbinmanager.cpp index 476ea81..228d466 100644
--- a/libk3b/core/k3bexternalbinmanager.cpp
+++ b/libk3b/core/k3bexternalbinmanager.cpp
@@ -32,6 +32,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <stdlib.h>
+#include <grp.h>
 #endif
 
 
@@ -59,7 +60,7 @@ public:
 
     ExternalProgram& program;
     QString path;
-    bool permissions;
+    QString needGroup;
     Version version;
     QString copyright;
     QStringList features;
@@ -86,14 +87,14 @@ const K3b::Version& K3b::ExternalBin::version() const
     return d->version;
 }
 
-void K3b::ExternalBin::setPermissions( const bool value )
+void K3b::ExternalBin::setNeedGroup( const QString& name )
 {
-    d->permissions = value;
+    d->needGroup = name;
 }
 
-bool K3b::ExternalBin::permissions() const
+const QString& K3b::ExternalBin::needGroup() const
 {
-    return d->permissions;
+    return d->needGroup;
 }
 
 void K3b::ExternalBin::setCopyright( const QString& copyright )
@@ -345,7 +346,7 @@ bool K3b::SimpleExternalProgram::scan( const QString& p )
     if ( QFile::exists( path ) ) {
         K3b::ExternalBin* bin = new ExternalBin( *this, path );
 
-        if ( ( !scanVersion( *bin ) || !scanFeatures( *bin ) ) && bin->permissions() \
) { +        if ( ( !scanVersion( *bin ) || !scanFeatures( *bin ) ) && \
bin->needGroup().isEmpty() )  {  delete bin;
             return false;
         }
@@ -367,13 +368,22 @@ bool K3b::SimpleExternalProgram::scanVersion( ExternalBin& bin \
) const  vp << bin.path() << "--version";
     if( vp.execute( EXECUTE_TIMEOUT ) < 0 ) {
         if( vp.error() == 0 ) {
-            kDebug() << "Insufficient permissions for " << bin.path();
-            bin.setPermissions( false );
+            kDebug() << "Insufficient permissions for" << bin.path();
+            // try to get real group or set fictive group to make
+            // K3b::SystemProblemDialog::checkSystem work
+            struct stat st;
+            if( !::stat( QFile::encodeName(bin.path()), &st ) ) {
+                QString group( getgrgid( st.st_gid )->gr_name );
+                kDebug() << "Should be member of \"" << group << "\"";
+                bin.setNeedGroup( group.isEmpty() ? "N/A" : group );
+            } else
+                bin.setNeedGroup( "N/A" );
         }
         return false;
     }
 
-    bin.setPermissions( true );
+    // set empty group to make K3b::SystemProblemDialog::checkSystem work
+    bin.setNeedGroup( "" );
     QString s = QString::fromLocal8Bit( vp.readAll() );
     bin.setVersion( parseVersion( s, bin ) );
     bin.setCopyright( parseCopyright( s, bin ) );
@@ -575,15 +585,15 @@ const K3b::ExternalBin* K3b::ExternalBinManager::binObject( \
const QString& name  }
 
 
-bool K3b::ExternalBinManager::binPermissions( const QString& name )
+QString K3b::ExternalBinManager::binNeedGroup( const QString& name )
 {
     if( d->programs.constFind( name ) == d->programs.constEnd() )
-        return false;
+        return 0;
 
     if( d->programs[name]->defaultBin() != 0 )
-        return d->programs[name]->defaultBin()->permissions();
+        return d->programs[name]->defaultBin()->needGroup();
 
-    return false;
+    return 0;
 }
 
 
diff --git a/libk3b/core/k3bexternalbinmanager.h \
b/libk3b/core/k3bexternalbinmanager.h index 9d4b504..ff9a87b 100644
--- a/libk3b/core/k3bexternalbinmanager.h
+++ b/libk3b/core/k3bexternalbinmanager.h
@@ -41,8 +41,8 @@ namespace K3b {
         ExternalBin( ExternalProgram& program, const QString& path );
         virtual ~ExternalBin();
 
-        void setPermissions( const bool value );
-        bool permissions() const;
+        void setNeedGroup( const QString& name );
+        const QString& needGroup() const;
 
         void setVersion( const Version& version );
         const Version& version() const;
@@ -213,7 +213,7 @@ namespace K3b {
         bool foundBin( const QString& name );
         QString binPath( const QString& name );
         const ExternalBin* binObject( const QString& name );
-        bool binPermissions( const QString& name );
+        QString binNeedGroup( const QString& name );
         const ExternalBin* mostRecentBinObject( const QString& name );
 
         ExternalProgram* program( const QString& ) const;
diff --git a/src/k3bsystemproblemdialog.cpp b/src/k3bsystemproblemdialog.cpp
index ccef75c..def7443 100644
--- a/src/k3bsystemproblemdialog.cpp
+++ b/src/k3bsystemproblemdialog.cpp
@@ -199,12 +199,12 @@ void K3b::SystemProblemDialog::checkSystem( QWidget* parent, \
NotificationLevel l  }
     else {
         // 1. cdrecord, cdrdao
-        if( !k3bcore->externalBinManager()->binPermissions( "cdrecord" ) ) {
+        if( !k3bcore->externalBinManager()->binNeedGroup( "cdrecord" ).isEmpty() ) {
             problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                i18n("Insufficient permissions for %1 \
executable: %2",QString("cdrecord"),k3bcore->externalBinManager()->binPath("cdrecord")),
                
                                                i18n("K3b uses cdrecord to actually \
                write CDs."),
                                                i18n("Check permissions via Settings \
                -> Configure K3b... -> Programs -> Permissions. "
-                                                    "If K3b's default value is set \
make sure you are member of \"cdrom\" group.") ) ); +                                 \
"If K3b's default value is set make sure you are member of \"%1\" group.", \
k3bcore->externalBinManager()->binNeedGroup( "cdrecord" )) ) );  }
         else if( !k3bcore->externalBinManager()->foundBin( "cdrecord" ) ) {
             problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
@@ -261,12 +261,12 @@ void K3b::SystemProblemDialog::checkSystem( QWidget* parent, \
NotificationLevel l  #endif
         }
 
-        if( !k3bcore->externalBinManager()->binPermissions( "cdrdao" ) ) {
+        if( !k3bcore->externalBinManager()->binNeedGroup( "cdrdao" ).isEmpty() ) {
             problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                i18n("Insufficient permissions for %1 \
                executable: \
                %2",QString("cdrdao"),k3bcore->externalBinManager()->binPath("cdrdao")),
                
                                                i18n("K3b uses cdrdao to actually \
                write CDs."),
                                                i18n("Check permissions via Settings \
                -> Configure K3b... -> Programs -> Permissions. "
-                                                    "If K3b's default value is set \
make sure you are member of \"cdrom\" group.") ) ) ; +                                \
"If K3b's default value is set make sure you are member of \"%1\" group.", \
k3bcore->externalBinManager()->binNeedGroup( "cdrdao" )) ) ) ;  }
 
         else if( !k3bcore->externalBinManager()->foundBin( "cdrdao" ) ) {
@@ -295,14 +295,14 @@ void K3b::SystemProblemDialog::checkSystem( QWidget* parent, \
NotificationLevel l  
     if( !k3bcore->deviceManager()->dvdWriter().isEmpty() ) {
 
-        if( !k3bcore->externalBinManager()->binPermissions( "growisofs" ) ) {
+        if( !k3bcore->externalBinManager()->binNeedGroup( "growisofs" ).isEmpty() ) \
                {
             problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                i18n("Insufficient permissions for %1 \
executable: %2",QString("growisofs"),k3bcore->externalBinManager()->binPath("growisofs")),
                
                                                i18n("K3b uses growisofs to actually \
                write DVDs. "
                                                     "Without growisofs you will not \
                be able to write DVDs. "
                                                     "Make sure to install at least \
                version 5.10."),
                                                i18n("Check permissions via Settings \
                -> Configure K3b... -> Programs -> Permissions. "
-                                                    "If K3b's default value is set \
make sure you are member of \"cdrom\" group.") ) ); +                                 \
"If K3b's default value is set make sure you are member of \"%1\" group.", \
k3bcore->externalBinManager()->binNeedGroup( "growisofs" )) ) );  } 
 
         else if( !k3bcore->externalBinManager()->foundBin( "growisofs" ) ) {
@@ -466,7 +466,7 @@ void K3b::SystemProblemDialog::checkSystem( QWidget* parent, \
NotificationLevel l  }
     }
 
-    if( dvd_r_dl && k3bcore->externalBinManager()->foundBin( "growisofs" ) && \
k3bcore->externalBinManager()->binPermissions( "growisofs" )) { +    if( dvd_r_dl && \
k3bcore->externalBinManager()->foundBin( "growisofs" ) && \
                k3bcore->externalBinManager()->binNeedGroup( "growisofs" ).isEmpty() \
                ) {
         if( k3bcore->externalBinManager()->binObject( "growisofs" )->version() < \
                K3b::Version( 6, 0 ) ) {
             problems.append( K3b::SystemProblem( K3b::SystemProblem::NON_CRITICAL,
                                                i18n("Used %1 version %2 is \
outdated",QString("growisofs"),k3bcore->externalBinManager()->binObject( "growisofs" \
)->version()),


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic