@ -19,10 +19,10 @@
# include "CalamaresUtilsSystem.h"
# include "utils/Logger.h"
# include "GlobalStorage.h"
# include "JobQueue.h"
# include "Settings.h"
# include "utils/Logger.h"
# include <QCoreApplication>
# include <QDir>
@ -34,8 +34,8 @@
# endif
# ifdef Q_OS_FREEBSD
# include <sys/types.h>
# include <sys/sysctl.h>
# include <sys/types.h>
# endif
/** @brief When logging commands, don't log everything.
@ -63,12 +63,18 @@ operator<<( QDebug& s, const RedactedList& l )
{
for ( const auto & item : l . list )
if ( item . startsWith ( " $6$ " ) )
{
s < < " <password> " ;
}
else
{
s < < item ;
}
}
else
{
s < < l . list ;
}
return s ;
}
@ -92,8 +98,7 @@ System::System( bool doChroot, QObject* parent )
}
System : : ~ System ( )
{ }
System : : ~ System ( ) { }
System *
@ -118,9 +123,13 @@ System::mount( const QString& devicePath,
if ( devicePath . isEmpty ( ) | | mountPoint . isEmpty ( ) )
{
if ( devicePath . isEmpty ( ) )
{
cWarning ( ) < < " Can't mount an empty device. " ;
}
if ( mountPoint . isEmpty ( ) )
{
cWarning ( ) < < " Can't mount on an empty mountpoint. " ;
}
return static_cast < int > ( ProcessResult : : Code : : NoWorkingDirectory ) ;
}
@ -140,17 +149,20 @@ System::mount( const QString& devicePath,
QStringList args = { devicePath , mountPoint } ;
if ( ! filesystemName . isEmpty ( ) )
{
args < < " -t " < < filesystemName ;
}
if ( ! options . isEmpty ( ) )
{
args < < " -o " < < options ;
}
return QProcess : : execute ( program , args ) ;
}
ProcessResult
System : : runCommand (
System : : RunLocation location ,
System : : runCommand ( System : : RunLocation location ,
const QStringList & args ,
const QString & workingPath ,
const QString & stdInput ,
@ -158,10 +170,10 @@ System::runCommand(
{
QString output ;
Calamares : : GlobalStorage * gs = Calamares : : JobQueue : : instance ( ) ? Calamares : : JobQueue : : instance ( ) - > globalStorage ( ) : nullptr ;
Calamares : : GlobalStorage * gs
= Calamares : : JobQueue : : instance ( ) ? Calamares : : JobQueue : : instance ( ) - > globalStorage ( ) : nullptr ;
if ( ( location = = System : : RunLocation : : RunInTarget ) & &
( ! gs | | ! gs - > contains ( " rootMountPoint " ) ) )
if ( ( location = = System : : RunLocation : : RunInTarget ) & & ( ! gs | | ! gs - > contains ( " rootMountPoint " ) ) )
{
cWarning ( ) < < " No rootMountPoint in global storage " ;
return ProcessResult : : Code : : NoWorkingDirectory ;
@ -197,7 +209,9 @@ System::runCommand(
if ( ! workingPath . isEmpty ( ) )
{
if ( QDir ( workingPath ) . exists ( ) )
{
process . setWorkingDirectory ( QDir ( workingPath ) . absolutePath ( ) ) ;
}
else
{
cWarning ( ) < < " Invalid working directory: " < < workingPath ;
@ -219,10 +233,10 @@ System::runCommand(
}
process . closeWriteChannel ( ) ;
if ( ! process . waitForFinished ( timeoutSec > std : : chrono : : seconds : : zero ( ) ? ( std : : chrono : : milliseconds ( timeoutSec ) . count ( ) ) : - 1 ) )
if ( ! process . waitForFinished (
timeoutSec > std : : chrono : : seconds : : zero ( ) ? ( std : : chrono : : milliseconds ( timeoutSec ) . count ( ) ) : - 1 ) )
{
cWarning ( ) . noquote ( ) . nospace ( ) < < " Timed out. Output so far: \n " < <
process . readAllStandardOutput ( ) ;
cWarning ( ) . noquote ( ) . nospace ( ) < < " Timed out. Output so far: \n " < < process . readAllStandardOutput ( ) ;
return ProcessResult : : Code : : TimedOut ;
}
@ -252,7 +266,8 @@ System::targetPath( const QString& path ) const
if ( doChroot ( ) )
{
Calamares : : GlobalStorage * gs = Calamares : : JobQueue : : instance ( ) ? Calamares : : JobQueue : : instance ( ) - > globalStorage ( ) : nullptr ;
Calamares : : GlobalStorage * gs
= Calamares : : JobQueue : : instance ( ) ? Calamares : : JobQueue : : instance ( ) - > globalStorage ( ) : nullptr ;
if ( ! gs | | ! gs - > contains ( " rootMountPoint " ) )
{
@ -317,7 +332,9 @@ System::getTotalMemoryB() const
int r = sysinfo ( & i ) ;
if ( r )
{
return qMakePair ( 0 , 0.0 ) ;
}
return qMakePair ( quint64 ( i . mem_unit ) * quint64 ( i . totalram ) , 1.1 ) ;
# elif defined( Q_OS_FREEBSD )
@ -326,7 +343,9 @@ System::getTotalMemoryB() const
int r = sysctlbyname ( " vm.kmem_size " , & memsize , & s , NULL , 0 ) ;
if ( r )
{
return qMakePair ( 0 , 0.0 ) ;
}
return qMakePair ( memsize , 1.01 ) ;
# else
@ -376,40 +395,45 @@ ProcessResult::explainProcess( int ec, const QString& command, const QString& ou
using Calamares : : JobResult ;
if ( ec = = 0 )
{
return JobResult : : ok ( ) ;
}
QString outputMessage = output . isEmpty ( )
? QCoreApplication : : translate ( " ProcessResult " , " \n There was no output from the command. " )
: ( QCoreApplication : : translate ( " ProcessResult " , " \n Output: \n " ) + output ) ;
if ( ec = = static_cast < int > ( ProcessResult : : Code : : Crashed ) ) //Crash!
return JobResult : : error ( QCoreApplication : : translate ( " ProcessResult " , " External command crashed. " ) ,
QCoreApplication : : translate ( " ProcessResult " , " Command <i>%1</i> crashed." )
. arg ( command )
return JobResult : : error (
QCoreApplication : : translate ( " ProcessResult " , " External command crashed." ) ,
QCoreApplication : : translate ( " ProcessResult " , " Command <i>%1</i> crashed. " ) . arg ( command )
+ outputMessage ) ;
if ( ec = = static_cast < int > ( ProcessResult : : Code : : FailedToStart ) )
return JobResult : : error ( QCoreApplication : : translate ( " ProcessResult " , " External command failed to start. " ) ,
QCoreApplication : : translate ( " ProcessResult " , " Command <i>%1</i> failed to start." )
. arg ( command ) ) ;
return JobResult : : error (
QCoreApplication : : translate ( " ProcessResult " , " External command failed to start." ) ,
QCoreApplication : : translate ( " ProcessResult " , " Command <i>%1</i> failed to start. " ) . arg ( command ) ) ;
if ( ec = = static_cast < int > ( ProcessResult : : Code : : NoWorkingDirectory ) )
return JobResult : : error ( QCoreApplication : : translate ( " ProcessResult " , " Internal error when starting command. " ) ,
return JobResult : : error (
QCoreApplication : : translate ( " ProcessResult " , " Internal error when starting command. " ) ,
QCoreApplication : : translate ( " ProcessResult " , " Bad parameters for process job call. " ) ) ;
if ( ec = = static_cast < int > ( ProcessResult : : Code : : TimedOut ) )
return JobResult : : error ( QCoreApplication : : translate ( " ProcessResult " , " External command failed to finish. " ) ,
return JobResult : : error (
QCoreApplication : : translate ( " ProcessResult " , " External command failed to finish. " ) ,
QCoreApplication : : translate ( " ProcessResult " , " Command <i>%1</i> failed to finish in %2 seconds. " )
. arg ( command )
. arg ( timeout . count ( ) )
+ outputMessage ) ;
//Any other exit code
return JobResult : : error ( QCoreApplication : : translate ( " ProcessResult " , " External command finished with errors. " ) ,
return JobResult : : error (
QCoreApplication : : translate ( " ProcessResult " , " External command finished with errors. " ) ,
QCoreApplication : : translate ( " ProcessResult " , " Command <i>%1</i> finished with exit code %2. " )
. arg ( command )
. arg ( ec )
+ outputMessage ) ;
}
} // namespace
} // namespace CalamaresUtils