[libcalamares] Fix file-reading from target system
readTargetFile was not fully reading files because of an incorrect EOF check. This could cause /etc/openswap.conf files to be truncated and hibernation to fail on installed systems.
This commit is contained in:
parent
55dcd831bc
commit
73462d9214
@ -169,7 +169,7 @@ System::readTargetFile( const QString& path ) const
|
|||||||
|
|
||||||
QTextStream in( &f );
|
QTextStream in( &f );
|
||||||
QStringList l;
|
QStringList l;
|
||||||
while ( !f.atEnd() )
|
while ( !in.atEnd() )
|
||||||
{
|
{
|
||||||
l << in.readLine();
|
l << in.readLine();
|
||||||
}
|
}
|
||||||
|
@ -1043,7 +1043,7 @@ file_setup( const QTemporaryDir& tempRoot )
|
|||||||
void
|
void
|
||||||
LibCalamaresTests::testReadWriteFile()
|
LibCalamaresTests::testReadWriteFile()
|
||||||
{
|
{
|
||||||
static const QByteArray otherContents( "derp\n" );
|
static const QByteArray otherContents( "first\nsecond\n" );
|
||||||
|
|
||||||
QTemporaryDir tempRoot( QDir::tempPath() + QStringLiteral( "/test-job-XXXXXX" ) );
|
QTemporaryDir tempRoot( QDir::tempPath() + QStringLiteral( "/test-job-XXXXXX" ) );
|
||||||
auto* ss = file_setup( tempRoot );
|
auto* ss = file_setup( tempRoot );
|
||||||
@ -1080,15 +1080,16 @@ LibCalamaresTests::testReadWriteFile()
|
|||||||
QFileInfo fi( fullPath.path() );
|
QFileInfo fi( fullPath.path() );
|
||||||
QVERIFY( fi.exists() );
|
QVERIFY( fi.exists() );
|
||||||
QVERIFY( fi.isFile() );
|
QVERIFY( fi.isFile() );
|
||||||
QCOMPARE( fi.size(), 5 );
|
QCOMPARE( fi.size(), 13 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now it's been written, we can read it, too
|
// Now it's been written, we can read it, too
|
||||||
{
|
{
|
||||||
auto contents = ss->readTargetFile( "test0" );
|
auto contents = ss->readTargetFile( "test0" );
|
||||||
QVERIFY( !contents.isEmpty() );
|
QVERIFY( !contents.isEmpty() );
|
||||||
QCOMPARE( contents.count(), 1 );
|
QCOMPARE( contents.count(), 2 );
|
||||||
QCOMPARE( contents[ 0 ], QStringLiteral( "derp" ) ); // No trailing \n
|
QCOMPARE( contents[ 0 ], QStringLiteral( "first" ) ); // No trailing \n
|
||||||
|
QCOMPARE( contents[ 1 ], QStringLiteral( "second" ) ); // No trailing \n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user