Add some guesswork to acquire a part node from a fstab entry for /home.

This commit is contained in:
Teo Mrnjavac 2016-07-08 18:22:55 +02:00
parent f2f5a18984
commit 5fe5b8a4f3
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,90 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "OsproberEntry.h"
#include <QProcess>
QString
OsproberEntry::homePartitionPath()
{
if ( fstab.isEmpty() )
return QString();
foreach ( const FstabEntry& entry, fstab )
{
if ( entry.mountPoint == "/home" )
{
QProcess readlink;
QString partPath;
if ( entry.partitionNode.startsWith( "/dev" ) ) // plain dev node
{
partPath = entry.partitionNode;
}
else if ( entry.partitionNode.startsWith( "LABEL=" ) )
{
partPath = entry.partitionNode.mid( 6 );
partPath.remove( "\"" );
partPath.replace( "\\040", "\\ " );
partPath.prepend( "/dev/disk/by-label/" );
}
else if ( entry.partitionNode.startsWith( "UUID=" ) )
{
partPath = entry.partitionNode.mid( 5 );
partPath.remove( "\"" );
partPath = partPath.toLower();
partPath.prepend( "/dev/disk/by-uuid/" );
}
else if ( entry.partitionNode.startsWith( "PARTLABEL=" ) )
{
partPath = entry.partitionNode.mid( 10 );
partPath.remove( "\"" );
partPath.replace( "\\040", "\\ " );
partPath.prepend( "/dev/disk/by-partlabel/" );
}
else if ( entry.partitionNode.startsWith( "PARTUUID=" ) )
{
partPath = entry.partitionNode.mid( 9 );
partPath.remove( "\"" );
partPath = partPath.toLower();
partPath.prepend( "/dev/disk/by-partuuid/" );
}
// At this point we either have /dev/sda1, or /dev/disk/by-something/...
if ( partPath.startsWith( "/dev/disk/by-" ) ) // we got a fancy node
{
readlink.start( "readlink", { "-en", partPath });
if ( !readlink.waitForStarted( 1000 ) )
return QString();
if ( !readlink.waitForFinished( 1000 ) )
return QString();
if ( readlink.exitCode() != 0 || readlink.exitStatus() != QProcess::NormalExit )
return QString();
partPath = QString::fromLocal8Bit(
readlink.readAllStandardOutput() ).trimmed();
}
return partPath;
}
}
return QString();
}

View File

@ -40,6 +40,8 @@ struct OsproberEntry
bool canBeResized;
QStringList line;
FstabEntryList fstab;
QString homePartitionPath();
};
typedef QList< OsproberEntry > OsproberEntryList;