diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index b290b62c5..301d20b33 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -147,6 +147,30 @@ System::createTargetFile( const QString& path, const QByteArray& contents, Write return CreationResult( QFileInfo( f ).canonicalFilePath() ); } +QStringList +System::readTargetFile( const QString& path ) const +{ + const QString completePath = targetPath( path ); + if ( completePath.isEmpty() ) + { + return QStringList(); + } + + QFile f( completePath ); + if ( !f.open( QIODevice::ReadOnly ) ) + { + return QStringList(); + } + + QTextStream in( &f ); + QStringList l; + while ( !f.atEnd() ) + { + l << in.readLine(); + } + return l; +} + void System::removeTargetFile( const QString& path ) const { diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index e11ecae05..1bb5629d1 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -287,6 +287,24 @@ public: */ DLLEXPORT void removeTargetFile( const QString& path ) const; + /** @brief Reads a file from the target system. + * + * @param path Path to the file; this is interpreted from the root of + * the target system (@see targetPath()). + * + * Does no error checking, and returns an empty list if the file does + * not exist. + * + * NOTE: This function is now basically the same as QFile::readAll(), + * splitting into lines, but Calamares may need to change + * permissions or raise privileges to actually read the file, + * which is why there is an API. + * + * NOTE: Since this buffers the whole file in memory, reading big files + * is not recommended. + */ + DLLEXPORT QStringList readTargetFile( const QString& path ) const; + /** @brief Ensure that the directory @p path exists * * @param path a full pathname to a desired directory.