[machineid] Refactor workers, demand absolute paths

This commit is contained in:
Adriaan de Groot 2019-10-04 17:43:48 +02:00
parent 12107b3113
commit 9e359c98a9

View File

@ -29,16 +29,34 @@
namespace MachineId namespace MachineId
{ {
static inline bool
isAbsolutePath( const QString& fileName )
{
return fileName.startsWith( '/' );
}
// might need to use a helper to remove the file // might need to use a helper to remove the file
void void
removeFile( const QString& rootMountPoint, const QString& fileName ) removeFile( const QString& rootMountPoint, const QString& fileName )
{
if ( isAbsolutePath( fileName ) )
{ {
QFile::remove( rootMountPoint + fileName ); QFile::remove( rootMountPoint + fileName );
} }
// Otherwise, do nothing
}
Calamares::JobResult Calamares::JobResult
copyFile( const QString& rootMountPoint, const QString& fileName ) copyFile( const QString& rootMountPoint, const QString& fileName )
{ {
if ( !isAbsolutePath( fileName ) )
{
return Calamares::JobResult::internalError(
QObject::tr( "File not found" ),
QObject::tr( "Path <pre>%1</pre> must be an absolute path." ).arg( fileName ),
0 );
}
QFile f( fileName ); QFile f( fileName );
if ( !f.exists() ) if ( !f.exists() )
{ {