[partition] Fix parsing of partition size in partition layout

When setting the size of a partition without indicating the unit, two
problems occur:

- the size is parsed as an integer, not as a string, hence the
configuration parsing fails
- the size parser doesn't recognize the fact that the size has no units
and defaults to 100%

This patch fixes the configuration parsing as well as the size string
parsing.

Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
This commit is contained in:
Arnaud Ferraris 2019-02-01 14:02:40 +01:00
parent 18bb71aceb
commit cf45d55b32
2 changed files with 24 additions and 4 deletions

View file

@ -57,11 +57,18 @@ parseSizeString( QString sizeString, PartitionLayout::SizeUnit *unit )
{
double value;
bool ok;
QString valueString;
QString unitString;
QRegExp rx( "[KkMmGg%]" );
int pos = rx.indexIn( sizeString );
QString valueString = sizeString.mid( 0, pos );
QString unitString = sizeString.mid( pos );
if (pos > 0)
{
valueString = sizeString.mid( 0, pos );
unitString = sizeString.mid( pos );
}
else
valueString = sizeString;
value = valueString.toDouble( &ok );
if ( !ok )