[partition] Improve logging in clearmounts job

This commit is contained in:
Adriaan de Groot 2021-06-18 16:18:06 +02:00
parent 432154e50a
commit 7deb6c0e9e

View File

@ -43,6 +43,7 @@ ClearTempMountsJob::prettyStatusMessage() const
Calamares::JobResult Calamares::JobResult
ClearTempMountsJob::exec() ClearTempMountsJob::exec()
{ {
Logger::Once o;
// Fetch a list of current mounts to Calamares temporary directories. // Fetch a list of current mounts to Calamares temporary directories.
QList< QPair< QString, QString > > lst; QList< QPair< QString, QString > > lst;
QFile mtab( "/etc/mtab" ); QFile mtab( "/etc/mtab" );
@ -51,23 +52,27 @@ ClearTempMountsJob::exec()
return Calamares::JobResult::error( tr( "Cannot get list of temporary mounts." ) ); return Calamares::JobResult::error( tr( "Cannot get list of temporary mounts." ) );
} }
cDebug() << "Opened mtab. Lines:"; cVerbose() << o << "Opened mtab. Lines:";
QTextStream in( &mtab ); QTextStream in( &mtab );
QString lineIn = in.readLine(); QString lineIn = in.readLine();
while ( !lineIn.isNull() ) while ( !lineIn.isNull() )
{ {
QStringList line = lineIn.split( ' ', SplitSkipEmptyParts ); QStringList line = lineIn.split( ' ', SplitSkipEmptyParts );
cDebug() << line.join( ' ' ); cVerbose() << o << line.join( ' ' );
QString device = line.at( 0 ); QString device = line.at( 0 );
QString mountPoint = line.at( 1 ); QString mountPoint = line.at( 1 );
if ( mountPoint.startsWith( "/tmp/calamares-" ) ) if ( mountPoint.startsWith( "/tmp/calamares-" ) )
{ {
cDebug() << "INSERTING pair (device, mountPoint)" << device << mountPoint;
lst.append( qMakePair( device, mountPoint ) ); lst.append( qMakePair( device, mountPoint ) );
} }
lineIn = in.readLine(); lineIn = in.readLine();
} }
if ( lst.empty() )
{
return Calamares::JobResult::ok();
}
std::sort( std::sort(
lst.begin(), lst.end(), []( const QPair< QString, QString >& a, const QPair< QString, QString >& b ) -> bool { lst.begin(), lst.end(), []( const QPair< QString, QString >& a, const QPair< QString, QString >& b ) -> bool {
return a.first > b.first; return a.first > b.first;
@ -76,10 +81,10 @@ ClearTempMountsJob::exec()
QStringList goodNews; QStringList goodNews;
QProcess process; QProcess process;
foreach ( auto line, lst ) for ( const auto& line : qAsConst( lst ) )
{ {
QString partPath = line.second; QString partPath = line.second;
cDebug() << "Will try to umount path" << partPath; cDebug() << o << "Will try to umount path" << partPath;
process.start( "umount", { "-lv", partPath } ); process.start( "umount", { "-lv", partPath } );
process.waitForFinished(); process.waitForFinished();
if ( process.exitCode() == 0 ) if ( process.exitCode() == 0 )
@ -92,7 +97,7 @@ ClearTempMountsJob::exec()
ok.setMessage( tr( "Cleared all temporary mounts." ) ); ok.setMessage( tr( "Cleared all temporary mounts." ) );
ok.setDetails( goodNews.join( "\n" ) ); ok.setDetails( goodNews.join( "\n" ) );
cDebug() << "ClearTempMountsJob finished. Here's what was done:\n" << goodNews.join( "\n" ); cDebug() << o << "ClearTempMountsJob finished. Here's what was done:\n" << Logger::DebugList( goodNews );
return ok; return ok;
} }